Alon Shmiel
Alon Shmiel

Reputation: 7121

update a row of mysql table

I am trying to update my table 'total':

in the row of id = 1, I want to update the value of 'days_left' to be 47.

String values_to_update = "UPDATE total SET days_left = '47' where id = '1'";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, "root", "Admin");
PreparedStatement ps = con.prepareStatement(values_to_update);
con.close();

Why isn't it updated?

Upvotes: 0

Views: 89

Answers (3)

xagyg
xagyg

Reputation: 9711

Do ...

ps.executeUpdate()

... before you close the connection. It doesn't look like you need a prepared statement either. A statement will do in your case.

Upvotes: 1

bhuang3
bhuang3

Reputation: 3633

At least, you need to execute your SQL statement via : ps.executeUpdate();

Upvotes: 1

hd1
hd1

Reputation: 34657

You need to execute the prepared statement. Try:

ps.executeUpdate(); 
con.commit();

before you close the connection.

Upvotes: 1

Related Questions