Reputation: 21
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();
}
Upvotes: 2
Views: 58
Reputation: 77
//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)
Upvotes: 1