Note that there are some explanatory texts on larger screens.

plurals
  1. POJava : SQL syntax error for entering values in Table
    primarykey
    data
    text
    <p>i am trying to add two methods to <code>withdraw and deposit</code> money in Bank Class . My <code>Database name is javatest</code> . <code>table name is bank</code> and following is the code . Problem is that when i run this code compiler says <code>You have an error in your SQL syntax;</code> i did check code 3-4 times but really unable to get it please help me with it . </p> <pre><code>public static void main(String[] args) { Connection connection= null ; Statement stmt = null ; try { Class.forName("com.mysql.jdbc.Driver"); connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/javatest","root",""); stmt= connection.createStatement(); withdrawfromchecking(connection, stmt, new BigDecimal(100), 1); Depositinsaving(connection, stmt, new BigDecimal(444), 1); stmt.executeBatch(); System.out.println("Done"); } catch (ClassNotFoundException e) {e.getMessage();} catch (SQLException e) {e.printStackTrace();} finally { if(connection!=null){try {connection.close();} catch (SQLException e) {e.printStackTrace();}} if(stmt!=null){try {stmt.close();} catch (SQLException e) {e.printStackTrace();}} } } public static void withdrawfromchecking(Connection connection ,Statement stmt, BigDecimal amount , int id ) throws SQLException { stmt.addBatch("UPDATE bank SET checkingbalance = checkingbalance-"+amount+"WHERE id="+id); } public static void Depositinsaving(Connection connection ,Statement stmt, BigDecimal amount , int id ) throws SQLException { stmt.addBatch("UPDATE bank SET savingbalance = savingbalance+ "+amount+"WHERE id="+id); } } </code></pre> <p>Error comes for this line - <code>stmt.executeBatch();</code> when i run program </p> <p><strong>EDIT : Exact error statement</strong> </p> <blockquote> <p>java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id =1' at line 1 at com.mysql.jdbc.StatementImpl.executeBatch(StatementImpl.java:1193) at MyPackage.BankAccount.main(BankAccount.java:24) </p> </blockquote> <p><strong>in my code (line 24 is stmt.executeBatch();</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload