我正在尝试在我的表中插入记录。问题是它给出错误,如不完整的查询。我无法弄清楚这里的错误。 提前致谢
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String table="student";
Connection con = DriverManager.getConnection("jdbc:odbc:Service_Center","","");
PreparedStatement update = con.prepareStatement("INSERT into "+table+" () VALUES(?,?)");
update.setString(1,"Bhushan");
update.setString(2,"bhushan123");
update.executeUpdate();
System.out.println("Row is added");
答案 0 :(得分:2)
PreparedStatement update = con.prepareStatement
("INSERT into "+table+" (Call_Date,Call_Time,.....) VALUES(?,?,.....)");
update.setString(1,calldate);
update.setString(2,calltime);
答案 1 :(得分:0)
问题在于您有三列:From
,To
和Source
是MySQL保留字。因此,您必须将它们放入反引号中:
st.executeUpdate("INSERT into "+table+" (Call_Date,Call_Time,`Source`,RMA_No,Item_name,Item_MAG,Item_model,Item_SrNo,Booking_Desc,Customer_name,Customer_address,Customer_contact,Customer_email,Call_type,Call_mode,Assigned_to,Service_Charges_Required,Total_Service_Charges,Part_Required,Part_No,Part_Name,Part_Model,Part_Quantity,Part_Price_per_Unit,VAT,LBT,Total_Cost_Of_Part_Requirement,TravellingRequired,`From`,`To`,Distance,TravellingCost) VALUES('"+calldate+"','"+calltime+"','"+Source+"','"+rmaNo+"','"+itemName+"','"+item_MAG+"','"+item_Model+"','"+item_Sr_No+"','"+Booking_Desc+"','"+customer_Name+"','"+customer_Address+"','"+customer_contact+"','"+customer_email+"','"+calltype+"','"+callmode+"','"+assignedTo+"','"+servicetaxApplicable+"','"+totalCharge+"','"+partRequired+"','"+partNo+"','"+partName+"','"+partModel+"','"+partquantity+"','"+price+"','"+vat+"','"+lbt+"','"+total+"','"+travellingRequired+"','"+from+"','"+to+"','"+distance+"','"+expectedTravellingCost+"')");
更好 - 将这三列名称更改为非保留字.....