Shahab khan Shahab khan - 3 months ago 18
Java Question

How to update a particular row in ms access table using java netbeans?

I am trying to update particular row in ms access table.
I have updated data in ms access by using this query

"update simba SET Username=?,Password=?"
this will update the whole table in ms access,but i am trying to update a particular row and for updating a particular column i used this query in my code
String sql="update simba SET Username=?,Password=? Where Username='"+name1+"'and Password='"+pass1"'";
but it's giving me this error
";" expected
.

Here is my code:

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con=DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\MUHAMMAD SHAHAB\\real estate.accdb");
String name=fit.getText();
String pass=String.valueOf(dis.getPassword());
String name1=vis.getText();
String pass1=String.valueOf(viss.getPassword());
String sql="update simba SET Username=?,Password=? Where Username='"+name1+"'and Password='"+pass1"'";
PreparedStatement pst=con.prepareStatement(sql);
pst.setString(1,name);
pst.setString(2,pass);


What am i doing wrong?

Answer
String sql = "..." + pass1 + "'";
                           ^

You missed the plus sign in the end of a String literal assigned to your sql variable.