eclipse - Java JDBC SQLite update entry not working -


I have created a set of databases and tables in Excel using JDBC and SQL.

I am trying to update the table using the following code:

  public static zero update () {connection c = null; Description stmt = null; Try {class.forName ("org.sqlite.JDBC"); C = DriverManager.getConnection ("jdbc: sqlite: walktreckers dbb"); C.setAutoCommit (wrong); System.out.println ("The database was opened successfully"); Stmt = c.createStatement (); String SQL = "Update customer 2 set ADDRESS = Byron where phone = 2;"; Stmt.executeUpdate (SQL); C.commit (); Results reset rs = stmt.executeQuery ("select from customers";); While (rsnext ()) {int id = rs.getInt ("id"); String name = rs.getString ("name"); Int age = rs.getInt ("age"); String address = rs.getString ("address"); Float Pay = R. JF Float ("Salary"); System.out.println ("id =" + id); System.out.println ("NAME =" + name); System.out.println ("AG =" + Age); System.out.println ("ADDRESS =" + address); System.out.println ("salary =" + salary); Println (); } Rs.close (); Stmt.close (); C.close (); } Hold (exception e) {System.err.println (e.getClass (). GetName () + ":" + e.getMessage ()); System.exit (0); } System.out.println ("Completed successfully"); }   

As far as I can understand, I am using SQL Syntax I:

Update the table's customers 2 and enter that address as Byron Set where phone = 2

but the following error is taking place:

  java.sql.SQLException: there is no such column: Byron   

Who tells me that this is interpreting me by requesting to make a change in the column called byron, which does not consider it a code to say this?

According to the SQL syntax, value varchar is used with single quotation marks Update it so that:

  string sql = "update customer 2 = ADDRESS = Bayron where PHONE = 2;";   

to

  string sql = "update customer 2 set ADDRESS = 'Byron' from where phone = 2;";   

If you do not use single quotes, SQL assumes that you are trying to set a value using a different column and therefore throws this error:

  java.sql.SQLException: There is no such column: Byron   

ADVICE : ready for dynamic parameter queries Use the location

  at the created location stmt; String sql = "update customer 2 set ADDRESS = WHERE PHONE =?"; Stmt = c.prepareStatement (SQL); Stmt.setString (1, "Byron"); Stmt.setInt (2, 2); Stmt.executeUpdate ();    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -