下面是我的代码
String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=Store;IntegratedSecurity=True";//
// Declare the JDBC objects.
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(url);
sql = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=sql.executeQuery( "select * from 购买列表");
while(rs.next())
{
sql.execute("update 购买列表 set 确认=1 where 购买列表.商品编号="+rs.getLong("商品编号")); //就是这里,购买列表每次都只更新了第一条数据的确认列为1
}
}
// Handle any errors that may have occurred.
catch (Exception ee) {
ee.printStackTrace();
}
finally {
if (rs != null)
try {
rs.close();
} catch (Exception ee) {
}
if (sql != null)
try {
sql.close();
} catch (Exception ee) {
}
if (con != null)
try {
con.close();
} catch (Exception ee) {
}
}
//java报的异常时结果集已经关闭。
String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=Store;IntegratedSecurity=True";//
// Declare the JDBC objects.
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(url);
sql = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=sql.executeQuery( "select * from 购买列表");
while(rs.next())
{
sql.execute("update 购买列表 set 确认=1 where 购买列表.商品编号="+rs.getLong("商品编号")); //就是这里,购买列表每次都只更新了第一条数据的确认列为1
}
}
// Handle any errors that may have occurred.
catch (Exception ee) {
ee.printStackTrace();
}
finally {
if (rs != null)
try {
rs.close();
} catch (Exception ee) {
}
if (sql != null)
try {
sql.close();
} catch (Exception ee) {
}
if (con != null)
try {
con.close();
} catch (Exception ee) {
}
}
//java报的异常时结果集已经关闭。