java SQL参数问题Jdbc
我从用户那里获取输入并存储在两个不同的变量中。我正在用sql语句绑定参数。当我运行代码时,它给出了连接查询部分的问题
String CityA= null;
String CityB= null;
try {
CityA = readEntry(in, "Enter Origin City : ");
CityB = readEntry(in, "Enter Destination City : ");
// We treat this drop table specially to allow it to fail
// as it will the very first time we run this program
try {
String q = "SELECT f.FLNO,f.DISTANCE,TIMEDIFF(f.arrives,f.departs)
as Duration FROM FLIGHTS F"
+ " WHERE F.ORIGIN = "+CityA;
+ "AND f.DESTINATION = "+CityB;
System.out.println(q);
rset = stmt.executeQuery(q);
while (rset.next()) {
System.out.println(rset.getInt("FLNO") + ","
+ rset.getInt("Distance") + ","
+ rset.getTime("Duration"));
}
System.out.println("Done");
}
catch (SQLException e) {
// assume not there yet, so OK to continue
}
finally {
stmt.close();
}
# 1 楼答案
请查找查询代码:- 基本上你错过了
CityA
和AND
之间的空格# 2 楼答案
您的查询字符串中有一个输入错误-您错过了
'Los-Angeles'
和AND
之间的空格