使用Oracle的Java GUI

时间:2018-03-27 04:49:45

标签: java oracle jframe

问题:java.sql.SQLSyntaxErrorException: ORA-00913:值过多   注意:我在数据库中创建了4个表。 NID列作为外键连接到另一个表。 但它没有工作,所以问题和方法是什么?

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();
     }

1 个答案:

答案 0 :(得分:1)

//请指定要在其中插入数据的表的列名,如下所示

插入table_name(“id,”,“name”,“salary”)值(1,“XYZ”,2050.00)