更新预准备语句以更新java中的用户输入信息

时间:2017-10-24 11:56:48

标签: java jdbc

我收到的错误是:线程中的异常" AWT-EventQueue-0" java.lang.NullPointerException

字符串sourceURL =" jdbc:odbc:studentdb&#34 ;;             String driverName =" sun.jdbc.odbc.JdbcOdbcDriver";

        String BName = txtDate.getText();
        String AName = txtadd.getText();
        String CName = txtCon.getText();
        String Search = txtSeaNam.getText();
       try{ 
      Class.forName(driverName);
      Connection conn = DriverManager.getConnection(sourceURL,"","");

      Statement ins = conn.createStatement();
      String Insert = "UPDATE student SET Address = '%"+AName+"%', ContactDetails = '%"+CName+"%', DateOfBirth = '%"+BName+"%'"
              + " WHERE Name = '%"+Search+"%' and ContactDetails = '%"+Search+"%' and DateOfBirth = '%"+Search+"%'";
      PreparedStatement st = conn.prepareStatement(Insert);


      st.setString(1, BName);
      st.setString(2, AName);
      st.setString(3,CName);
      st.executeUpdate();

  }catch (SQLException | ClassNotFoundException e){
      System.out.println(e.toString());
  }

请帮助解决错误。谢谢

0 个答案:

没有答案