android 使用jdbc1.3.0 操作 sql server
String connectDB = "jdbc:jtds:sqlserver://172.16.1.15:1433;DatabaseName=YanBu";// 连接字符串换成这个 try { Class.forName("net.sourceforge.jtds.jdbc.Driver");//加载驱动换成这个 } catch (Exception e) { e.printStackTrace(); System.out.println("加载数据库引擎失败"); System.exit(0); } System.out.println("数据库驱动成功"); try { String user = "sa"; String password = "sa"; Connection con = DriverManager.getConnection(connectDB, user, password);// 连接数据库对象 System.out.println("连接数据库成功"); int i = 1; Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet resultSet = statement.executeQuery("select * from MaxSNs where Name = '质检单号'"); while (resultSet.next()) {//<code>ResultSet</code>最初指向第一行 System.out.println(resultSet.getInt("SN"));//输出第n行,列名为“test_id”的值 i += resultSet.getInt("SN"); resultSet.updateInt("SN",i); resultSet.updateRow(); } resultSet.close(); statement.close(); } catch (SQLException e) { e.printStackTrace(); }