日期:2014-05-20 浏览次数:20866 次
try {
Connection con =DBManager.getConn();
String sql="update t114stuinfo set salary=salary+? where stuName like ?";
PreparedStatement pstmt =con.prepareStatement(sql);
pstmt.setInt(1,1000);
pstmt.setString(2,"tt");
int x=pstmt.executeUpdate();
if(x>0){
System.out.println("更新成功");
}else{
System.out.println("更新失败");
}
pstmt.close();
con.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection con = DriverManager.getConnection(
"jdbc:jtds:sqlserver://localhost:1433/jiu", "sa", "1991721");
String sql =
"update admin set username = ? where username like ?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, "ninty");
pstmt.setString(2, "%n%");
int x = pstmt.executeUpdate();
if (x > 0) {
System.out.println("更新成功");
} else {
System.out.println("更新失败");
}
pstmt.close();
con.close();
------解决方案--------------------
你不用PreparedStatement 不行吗
或者不使用odbc桥
顺便问下楼上的
net.sourceforge.jtds.jdbc.Driver可以连odbc吗,没试过不了解