2014年5月22日星期四

Data jsp mysql database written in total mistake , seek help

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order values ​​(' null ',' movie_name ', '11: 00:00', '60 ', '1') 'at line 1
--- --- Solution --------------------------------------------
String sql = "insert into order ('sky', 'movie_name', '19: 00:00 ', '50', '1 ') values ​​(,???? , ) " ? ;


valuse field name written in front of you it looks like the data
------ Solution ---------------------- ----------------------
assuming your sql statement is properly decoded , then you copy this database sql statements directly re- execution , if it is not wrong that you have in your java code is the data layer to test , it is recommended behind each step are marked System.out.println ("1"), System.out. println ("2"), and so on where to cut off where there are problems
------ Solution ---------------- ----------------------------
not read
order keyword can not be used as table column names
so wrong
------ For reference only ------------------------------- --------
http://blog.csdn.net/id19870510/article/details/6259636 look is not
---- - For reference only ---------------------------------------

not ah
  	   String username=request.getParameter("username");  
      String movie_name=("movie_name");
      String time=request.getParameter("time");
      String price=request.getParameter("price");
      String number=request.getParameter("BuyNumber");


Connection conn;
PreparedStatement pstmt=null;
  try{
      Class.forName(driverClass).newInstance();
       conn=DriverManager.getConnection(url,user,password);
       String sql="insert into order values (?,?,?,?,?)";
       pstmt=conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
       pstmt.setString(1,username);
       pstmt.setString(2,movie_name);
       pstmt.setString(3,time);
       pstmt.setString(4,price);
       pstmt.setString(5,number);
       pstmt.executeUpdate();
       
       out.print("购买成功");
              }
              
              catch(SQLException e){
               e.printStackTrace();
         out.print("购买失败");
                                  }


------ For reference only ----------------------------------- ----
precompiled statement it has only a single parameter
pstmt = conn.prepareStatement (sql);
------ For reference only ------------------------- --------------

this is what I look for from the book , I try to say there are ways you , ah, ah nor
----- - For reference only ---------------------------------------
insert into order ( which fill you try to fill in the fields ) values ​​(?,?,?,?,?)

------ For reference only ---------------------------------- -----

 try{
      Class.forName(driverClass).newInstance();
       conn=DriverManager.getConnection(url,user,password);
       String sql="insert into order ('sky','movie_name','19:00:00','50','1') values (?,?,?,?,?)";
       pstmt=conn.prepareStatement(sql);

       pstmt.executeUpdate();
       
       out.print("购买成功");
              }
              
              catch(SQLException e){
               e.printStackTrace();
         out.print("购买失败");
                                  }


this is still being given : java.sql.SQLException: No value specified for parameter 1.
neighborhoods
------ For reference only --------------------------------- ------
stmt.executeUpdate("insert into tb_name (col1,col2,col2,col4) values ('"+var1+"','"+var2+"',"+var3+",'"+var4+"')");

perstmt = con.prepareStatement("insert into tb_name (col1,col2,col2,col4) values (?,?,?,?)");
perstmt.setString(1,var1);
perstmt.setString(2,var2);
perstmt.setString(3,var3);
perstmt.setString(4,var4);
perstmt.executeUpdate();

------ For reference only -------------------------- -------------

try 8L issued in accordance with the method , and does not work, or will complain
  Connection conn;
PreparedStatement pstmt=null;
  try{
      Class.forName(driverClass).newInstance();
       conn=DriverManager.getConnection(url,user,password);
       String sql="insert into order(username,movie_name,time,price,number) values (?,?,?,?,?)"; 
       pstmt=conn.prepareStatement(sql);
       pstmt.setString(1,username);
       pstmt.setString(2,movie_name);
       pstmt.setString(3,time);
       pstmt.setString(4,price);
       pstmt.setString(5,number);
       pstmt.executeUpdate();
       
       out.print("购买成功");
              }
              
              catch(SQLException e){
               e.printStackTrace();
         out.print("购买失败");
                                  }


error Content : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the ; right syntax to use near 'order (username, movie_name, time, price, number) values ​​(' sky ',' movie_name ', '11: 00:0' at line 1
------ For reference only ------------------------------------- -
I looked at the code you posted I suspect you may not have to decode your data , you try to use the page out.println (sql) or <% = sql%> ; output your sql statement output what you see in the end
------ For reference only -------------------- -------------------
String movie_name = ("movie_name"); What does this mean
------ For... reference only ---------------------------------------



sql statement seems to be the problem of decoding , the general feeling is skipped try the statement , do you have any good suggestions
------ For reference only --------- ------------------------------


agree
------ For reference only --------------------------------- ------

another table no problem
------ For reference only ---------------- -----------------------

you're so right , I change the name just fine ! ! ! Thank you reply , so I understand

没有评论:

发表评论