'DATE'无法保存“INTEGER”类型的值

时间:2016-11-01 22:42:27

标签: date

我已经设置了一个SQL数据库并使用'Date'作为我的列标题,它显然有自己的格式而不是整数或字符等。但是当我输入日期如2/11/2016时它给出了我错误信息 - 'DATE'不能保存'INTEGER'类型的值。有谁知道我应该使用什么代码?这是我的jsp。当我删除所有对日期的引用时,所有进入DB。

        <%    
            int tableNum = 0; 
            String firstName = null; 
            String lastName = null;
            String Address = null;
            int Phone = 0;
            java.sql.Date date = null;
            int People = 0;

            if (request.getParameter("table_num")!=null){
                tableNum = Integer.parseInt(request.getParameter("table_num"));
            }
            if (request.getParameter("first")!=null){
                firstName = request.getParameter("first");
            }
            if (request.getParameter("last")!=null){
                lastName = request.getParameter("last");
            }
            if (request.getParameter("address")!=null){
                Address = request.getParameter("address");
            }
            if (request.getParameter("phone")!=null){
                Phone = Integer.parseInt(request.getParameter("phone"));
            }
            if (request.getParameter("date")!=null){

               java.util.Date utilDate = new java.util.Date(request.getParameter("date"));

               date = new java.sql.Date(utilDate.getTime()); 
            }
            if (request.getParameter("people")!=null){
                People = Integer.parseInt(request.getParameter("people"));
            }
            if(tableNum != 0 && firstName != null && lastName != null && Address != null && Phone != 0 && date != null && People != 0){ 
                String URL = "jdbc:derby://localhost:1527/Reservations";  
                String USERNAME= "johnpaul";
                String PASSWORD= "purlease";
                Connection myCon = null;
                Statement ste = null;
                PreparedStatement preparedStmt = null;

                try{
                    Class.forName("org.apache.derby.jdbc.ClientDriver"); 
                    System.out.println("Connecting to DB...");
                    Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/Reservations","johnpaul", "purlease");
                    System.out.println("Connected successfuly");

                    System.out.println("Inserting records into table");      
                    Statement st = con.createStatement();
                    String query = "INSERT INTO CUSTOMER_RESERVATIONS(TABLE_NUM,FIRST_NAME,LAST_NAME,ADDRESS,TELEPHONE,DATE,NUMBER_IN_PARTY)VALUES(" + tableNum + "," + "'" + firstName + "'" + "," + "'" + lastName + "'" + ","  + "'" + Address + "'" + "," + Phone + "," + date + "," + People +")";


                    st.executeUpdate (query);  
                    System.out.println("Records inserted");


                   }catch(SQLException se){
                    se.printStackTrace();
                }catch(ClassNotFoundException se){
            //Handle errors for JDBC
                    se.printStackTrace();
            }catch(Exception e){
                //Handle errors for Class.forName
                     e.printStackTrace(); 

            }
            }            
         %>

0 个答案:

没有答案