我正试图编写一个servlet来对数据库进行查询,但当它运行时,出现以下错误:
java.sql.sqlsyntaxerrorexception:“field list”中的未知列“programmedescription”
代码:
response.setContentType("text/html; charset=UTF-8");
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String requestType= request.getParameter("requestType");
if (requestType == null) {
createDynPage(response, "Μη έγκυρος τύπος ερωτήματος");
}
if (requestType.equalsIgnoreCase("insert")) {
String descr = request.getParameter("descr");
String mins = request.getParameter("mins");
String sms = request.getParameter("sms");
String mb = request.getParameter("mb");
String pagio = request.getParameter("pagio");
String minstoall = request.getParameter("minstoall");
String costpermin = request.getParameter("costpermin");
String costpersms= request.getParameter("costpersms");
String costpermb = request.getParameter("costpermb");
int m = Integer.parseInt(mins);
int s = Integer.parseInt(sms);
int d = Integer.parseInt(mb);
float fc=Float.parseFloat(pagio);
int mta = Integer.parseInt(minstoall);
float cpm=Float.parseFloat(costpermin);
float cps=Float.parseFloat(costpersms);
float cpmb=Float.parseFloat(costpermb);
try {
Connection con = datasource.getConnection();
Statement stmt = con.createStatement();
StringBuilder x = new StringBuilder();
String insertStmt = "INSERT INTO CUSTOMERS (PROGRAMMEDescription, PROGRAMMESpeechTime, PROGRAMMESMSNumber, PROGRAMMEData, PROGRAMMEFixedCost, PROGRAMMESpeechTimeToAll, PROGRAMMECostPerMinute, PROGRAMMECostPerSMS, PROGRAMMECostPerMB)" +
" VALUES (";
insertStmt += "'" + descr + "',";
insertStmt += m + ",";
insertStmt += s + ",";
insertStmt += d + ",";
insertStmt += fc + ",";
insertStmt += mta + ",";
insertStmt += cpm + ",";
insertStmt += cps + ",";
insertStmt += cpmb + ")";
stmt.executeUpdate(insertStmt);
createDynPage(response, "Το πρόγραμμα δημιουργήθηκε επιτυχώς!");
stmt.close();
con.close();
} catch(SQLException sqle) {
sqle.printStackTrace();
}
} else {
createDynPage(response, "The request type parameter must be insert");
}
表格:
从代码和表中都可以看到,列 PROGRAMMEDescription
正常存在。我不能理解为什么java认为它没有。有什么想法吗?
1条答案
按热度按时间xdyibdwo1#
我想可能是因为这个字段不在数据库里!也许这次应该执行sql语句,并在数据库中执行一次,以确定该字段是否存在于数据库中!