import java.sql.*;
public class Login
{
public static void main(String args[]) throws SQLException
{
Connection con = null;
PreparedStatement stmt = null;
Statement st = null;
try {
Driver driver = new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(driver);
System.out.println("coneecting to the database:");
con = DriverManager.getConnection("driverURL","usrr","pass");
System.out.println("creating statement");
String sql = "Update abhi SET age = ? WHERE id = ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, 35);
stmt.setInt(2,102);
int rows = stmt.executeUpdate();
S.O.P("rows updated"+rows);
stmt.close();
String sql2;
sql2 = "select * from abhi";
st = con.createStatement();
ResultSet rs = st.executeQuery(sql2);
while(rs.next())
{
System.out.println("hi");
int age = rs.getInt("age");
System.out.println("age is"+age);
}
rs.close();
stmt.close();
con.close();
}
catch(SQLException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (st != null)
st.close();
}
catch(Exception e) {
// nthing to do
}
try {
if(con != null)
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("good bye johny");
}
}
这是我的代码,它运行良好,没有任何错误......但是在我的数据库中,它的 nt 更新值我无法理解为什么有任何机构帮助我解决为什么它的 nt 更新 id 为 102 的年龄值 .. .