ResultSet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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" ); } } |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步