码迷,mamicode.com
首页 > 其他好文 > 详细

ResultSet

时间:2015-09-04 19:50:35      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class ResultSetTest {
	private String driver;
	private String url;
	private String user;
	private String pass;

	public void initPara(String paraFile) throws Exception {
		Properties props = new Properties();
		props.load(new FileInputStream(paraFile));
		driver = props.getProperty("driver");
		url = props.getProperty("url");
		user = props.getProperty("username");
		pass = props.getProperty("password");
	}

	public void qurey(String sql) throws Exception {
		Class.forName(driver);
		try (Connection cnn = DriverManager.getConnection(url, user, pass);
				PreparedStatement pstmt = cnn.prepareStatement(sql,
						ResultSet.TYPE_SCROLL_INSENSITIVE,
						ResultSet.CONCUR_UPDATABLE);
				ResultSet rs = pstmt.executeQuery()) {
			rs.last();
			int rowCount = rs.getRow();
			for (int i = rowCount; i > 0; i--) {
				rs.absolute(i);
				System.out.println(rs.getString(1) + "\t" + rs.getString(2)
						+ "\t" + rs.getString(3) + "\t" + rs.getString(4));
				rs.updateString(2,"b"+i);
				rs.updateRow();
			
			}
		}
	}
	
	
	public static void main(String[] args) throws Exception{
		ResultSetTest rt = new ResultSetTest();
		rt.initPara("Mysql.ini");
		rt.qurey("select * from user");
	}

}

 

ResultSet

标签:

原文地址:http://www.cnblogs.com/masterlibin/p/4782195.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!