我有一个名为‘飞机’的数据库,里面有一个名为时间表的表。timeatable表具有text类型的fromcity列
Connection conn0=null;
PreparedStatement st0=null;
String sql0="SELECT FROM timetable where fromcity=?";
try{
Class.forName("com.mysql.jdbc.Driver");
conn0=DriverManager.getConnection(DB_URL,USER,PASS);
st0=conn0.prepareStatement(sql0);
st0.setString(1,city[i]);
ResultSet rs0=st0.executeQuery();
if(rs0.next())
{
System.out.println("flight exists");
}
else
{
System.out.println("fight does not exist");
}
}
catch(Exception et)
{
System.out.println("Error"+et.getMessage());
}
我得到了一个错误:
为什么我会收到这个错误
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM timetable where fromcity='1'' at line 1
发布于 2018-10-22 05:33:53
您忘记在查询中写入列名。
搞定,
SELECT * FROM timetable where fromcity=?"
而不是,
SELECT FROM timetable where fromcity=?"
https://stackoverflow.com/questions/52920077
复制相似问题