0
try {  
    Class.forName("com.mysql.jdbc.Driver");
    String connectionUrl = "jdbc:mysql://Localhost/basic_credit? autoReconnect=true&useSSL=false" ;

    Connection con = DriverManager.getConnection(connectionUrl,"root","superchan009");
    String sql="INSERT INTO new_table(date, time, customer_name, address, contact#1, contact#2, item_name, final_price, downpayment, remaining_balance, length_ofinstallment, payment_permonth, first_due, last_due)VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    PreparedStatement ps=con.prepareStatement(sql);

    ps.setString(1,jLabel16.getText());
    ps.setString(2,jLabel17.getText());
    ps.setString(3,tf1.getText());
    ps.setString(4,tf2.getText());
    ps.setString(5,tf3.getText());
    ps.setString(6,tf4.getText());
    ps.setString(7,tf6.getText());
    ps.setString(8,tf7.getText());
    ps.setString(9,tf8.getText());
    ps.setString(10,tf9.getText());
    ps.setString(11,tf10.getText());
    ps.setString(12,tf11.getText());
    ps.setString(13,tf12.getText());
    ps.setString(14,tf13.getText());

    ps.executeUpdate();
    JOptionPane.showMessageDialog(null,"DATA SAVED! THANK YOU!");

} catch (SQLException e) {
    System.out.println("SQL Exception: "+ e.toString());
} catch (ClassNotFoundException cE) {
    System.out.println("Class Not Found Exception: "+ cE.toString());
}
9
  • 2
    A space is missing before VALUES . Commented Apr 18, 2017 at 15:56
  • Please help me with this one. I've already omitted the quotations in "?" but stil, it isn't working. What's wrong? Commented Apr 18, 2017 at 15:57
  • 2
    contact#1 is unlikely to be a valid name without being escaped, what DB are you using? Commented Apr 18, 2017 at 15:58
  • @AlexK. : The URL suggests mySql . Commented Apr 18, 2017 at 15:59
  • 1
    replace contact#1 with `contact#1` (same for ..#2), you may need to do the same with date and time. Commented Apr 18, 2017 at 16:04

2 Answers 2

2

you are using # in column name is creating issue... you should remove # tag from column name and also correct it into database.

Sign up to request clarification or add additional context in comments.

Comments

0
try {  
    Class.forName("com.mysql.jdbc.Driver");
    String connectionUrl = "jdbc:mysql://Localhost/basic_credit? autoReconnect=true&useSSL=false" ;

    Connection con = DriverManager.getConnection(connectionUrl,"root","superchan009");
    String sql="INSERT INTO new_table(date, time, client_name, address, contact1, contact2, item_name, final_price, downpayment, remaining_balance, length_ofinstallment, payment_permonth, first_due, last_due) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    PreparedStatement ps=con.prepareStatement(sql);

    ps.setString(1,jLabel16.getText());
    ps.setString(2,jLabel17.getText());
    ps.setString(3,tf1.getText());
    ps.setString(4,tf2.getText());
    ps.setString(5,tf3.getText());
    ps.setString(6,tf4.getText());
    ps.setString(7,tf6.getText());
    ps.setString(8,tf7.getText());
    ps.setString(9,tf8.getText());
    ps.setString(10,tf9.getText());
    ps.setString(11,tf10.getText());
    ps.setString(12,tf11.getText());
    ps.setString(13,tf12.getText());
    ps.setString(14,tf13.getText());

    ps.executeUpdate();
    JOptionPane.showMessageDialog(null,"DATA SAVED! THANK YOU!");

} catch (SQLException e) {
    System.out.println("SQL Exception: "+ e.toString());
} catch (ClassNotFoundException cE) {
    System.out.println("Class Not Found Exception: "+ cE.toString());
}

SQL to JAVA connection is case sensitive if you're going to use special char "#" for column names.

1 Comment

Is this intended as an answer? If not, please edit your question instead; if it is an answer, then please add an explanation, not just code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.