Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDBC SQLite Update

Tags:

java

sqlite

jdbc

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..

like image 838
Hoou Avatar asked Jul 26 '26 14:07

Hoou


1 Answers

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)


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!