[英]Java JDBC program throwing SQL syntax error when fetching particular rows from a table
I have a database called 'airplane' inside which there is a table named timetable . 我有一个名为“ airplane”的数据库,其中有一个名为timetable的表。 The timeatable table has a column fromcity of text type
定时表格的文字类型为城市列
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());
}
I am getting the error: 我收到错误消息:
why am I getting this error 为什么我得到这个错误
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
You forgot to write column names in your query. 您忘记在查询中写列名。
Make it, 做了,
SELECT * FROM timetable where fromcity=?"
instead of, 代替,
SELECT FROM timetable where fromcity=?"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.