使用Netbeans将数据插入数据库表

时间:2018-10-24 12:01:17

标签: java netbeans

我陷入了困境,我连接了数据库并按照我认为的方式进行了一切编码,但是我在应用程序中输入了数据,但它没有显示在我的表中,这是我的数据库代码

尝试{             Class.forName(“ com.mysql.jdbc.Driver”);

       Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/gateaccesscontrol?autoReconnect=true&useSSL=false","root","root");
       String Sql = "insert into visitors values (?,?,?,?,?,?,?,?)"; 
       PreparedStatement pstmt = conn.prepareStatement(Sql);
       pstmt.setString(2,Datetxt.getText());
       pstmt.setString(3,Timetxt.getText());
       pstmt.setString(4, Nametxt.getText());
       pstmt.setString(5, Comptxt.getText());
       pstmt.setString(1,Regtxt.getText());
       pstmt.setInt(6,Integer.parseInt(Teltxt.getText()));
       pstmt.setString(7, Reasontxt.getText());
       pstmt.setString(8,Persontxt.getText());
       JOptionPane.showMessageDialog(null,"insertion successful");
       conn.close();


    }catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e);
    }

0 个答案:

没有答案