QueryRunner run = new QueryRunner( dataSource ); try { // Execute the SQL update statement and return the number of // inserts that were made int inserts = run.update( "INSERT INTO Person (name,height) VALUES (?,?)", "John Doe", 1.82 ); // The line before uses varargs and autoboxing to simplify the code // Now it's time to rise to the occation... int updates = run.update( "UPDATE Person SET height=? WHERE name=?", 2.05, "John Doe" ); // So does the line above } catch(SQLException sqle) { // Handle it }
不知道为什么会提示where附近错误,我根本就没用到where这个语句
[email protected]
我再试试看,谢谢
String sql = "insert into department(id,name) values(“12”,“name2”)";
qr.update(sql);如果没有问题,就是你DButil传参出了问题。
try {
String url = "jdbc:msql://200.210.220.1:1114/Demo";
Connection conn = DriverManager.getConnection(url,"","");
Statement st = conn.createStatement();
st.executeUpdate("INSERT INTO Customers " +
"VALUES (1001, 'Simpson', 'Mr.', 'Springfield', 2001)"); conn.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
try
{
// Execute the SQL update statement and return the number of
// inserts that were made
int inserts = run.update( "INSERT INTO Person (name,height) VALUES (?,?)",
"John Doe", 1.82 );
// The line before uses varargs and autoboxing to simplify the code // Now it's time to rise to the occation...
int updates = run.update( "UPDATE Person SET height=? WHERE name=?",
2.05, "John Doe" );
// So does the line above
}
catch(SQLException sqle) {
// Handle it
}