2

problem: java.sql.SQLSyntaxErrorException: ORA-00913: too many values Note: I create 4 table in the database. the NID column is connected as the foreign key to the other table. But it didn't work so whats the problem as well as the correct way?

try
      {

     Class.forName("oracle.jdbc.driver.OracleDriver");

     Connection con =  DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","test2","12345");
     System.out.println("Connected Successfully To Oracle");

  Statement st = con.createStatement();
   String sql= "Insert into cus values ('"+name.getText()+"','"+nid.getText()+"','"+age.getText()+"',"
           + "'"+sex.getActionCommand()+"','"+vill.getText()+"','"+thana.getText()+"',"
           + "'"+district.getText()+"','"+email.getText()+"')";
   String sql2="Insert into phone values ('"+phone.getText()+"')";
   String sql3="Insert into cost values ('"+fear.getText()+"')";
   String sql4="Insert into bus values ('"+seat.getText()+"','"+coach.getText()+"')";
       st.execute(sql);
       st.execute(sql2);
       st.execute(sql3);
       st.execute(sql4);


     System.out.println("Sucessfully inserted");
      con.close();
      st.close();


  }
     catch(Exception ex)
     {
        ex.printStackTrace();
     }
Farhana Naaz Ansari
  • 7,524
  • 26
  • 65
  • 105
  • 1
    prove scheme structure so that easily identify the error. mostly this cases your passing more values to the insert query. – yugi Mar 27 '18 at 04:58
  • Apart from what @yugi mentioned, try to use PreparedStatement to prevent [SQL Injection](https://stackoverflow.com/questions/1582161/how-does-a-preparedstatement-avoid-or-prevent-sql-injection) – Jacob Mar 27 '18 at 05:25

1 Answers1

1

//please specify the column names of table in which you are going to insert the data like below

insert into table_name("id,","name","salary") values(1,"XYZ",2050.00)

Amit Singh
  • 77
  • 1
  • 8