I'm new in jdbc sqlite. I would like to know how to execute an update. For example i have a table called people name, and occupation inside. Should i use PreparedStatement?
PreparedStatement change = conn.prepareStatement("Update people set name = ? ");
change.setString(1, "John");
ResultSet rs = stat.executeQuery("select * from people where name = 'Gandhi';");
while (rs.next()) {
System.out.println("name = " + rs.getString("name"));
System.out.println("job = " + rs.getString("occupation"));
}
rs.close();
conn.close();
I'd like to ask the proper way. Thanks you..
You are not "executing" the update. You need to call change.executeUpdate() in order to send the UPDATE statement to the engine.
(And as ZeroPage has pointed out: remove the ; in the SQL string)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With