标签:
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"); } }
标签:
原文地址:http://www.cnblogs.com/masterlibin/p/4782195.html