从jdatechooser获取值并将其添加到数据库java时出错

时间:2017-06-15 08:40:55

标签: java

如何显示jcalender?

如何从中获取所选值并将其添加到数据库?

从谷歌我发现了一个名为jcalender-1.4的文件。我已将它添加到jframe中,但当我尝试从中获取选定值并将其添加到数据库时,它会显示错误。创建表,但插入值时显示错误。显示插入方法中的例外。我试图通过注释insertData方法打印值db9的值,它显示为null。下面是我使用过的JCalender jar文件的链接。

https://www.dropbox.com/s/yxe86ylfm4u6be8/jcalendar-1.4.jar?dl=0

JButton btnNewButton = new JButton("New Reservation");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

        db1=textField.getText();
        db2=textField_1.getText();
        db3=textField_2.getText();
        db4=textField_3.getText();
        db5=textField_4.getText();
        db6=textField_5.getText();
        db7=textField_6.getText();
        db8=(String)comboBox.getSelectedItem();
        db9=dateChooser.getDate();
        db10=textField_7.getText();
        db11=(String)comboBox_1.getSelectedItem();
        db12=(String)comboBox_2.getSelectedItem();
        db13=dateChooser_1.getDate();
        db14=dateChooser_2.getDate();
        try {
            insertData();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        public static void createTable() throws Exception{
            try{
                Connection con=getConnection();
                PreparedStatement create =con.prepareStatement("CREATE TABLE IF NOT EXISTS hotelDetails(_id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,name varchar(65),"
                        + "surname varchar(65),address varchar(65),cnic varchar(65),mobileNo varchar(65),email varchar(65),city varchar(65),gender varchar(65),dob Date,country varchar(65),roomType varchar(65),"
                        + "roomNo varchar(65),checkin Date,checkout Date)");
                create.executeUpdate();
                System.out.println("Table Created");

            }catch(Exception e)
            {
                JOptionPane.showMessageDialog(null,"Table Not Created.Try Again","Error", JOptionPane.ERROR_MESSAGE);
            }
        } public static void insertData() throws Exception{
                try{
                    Connection con=getConnection();
                    PreparedStatement posted=con.prepareStatement("INSERT INTO hotelDetails(name,surname,address,cnic,mobileNo,email,city,gender,dob,country,roomType,roomNo,checkin,checkout)VALUES('"+db1+"','"+db2+"','"+db3+"','"+db4+"','"+db5+"','"+db6+"','"+db7+"','"+db8+"','"+db9+"','"+db10+"','"+db11+"','"+db12+"','"+db13+"','"+db14+"')");
                    posted.executeUpdate();
                    System.out.println("Values Inserted");

                }catch(Exception e)
                {
                    JOptionPane.showMessageDialog(null,"Can't Insert Data","Error", JOptionPane.ERROR_MESSAGE);
                }

            }

0 个答案:

没有答案