我有一个名为“飞机”的数据库,里面有一个名为“时间表”的表。TimeataTable表有一个文本类型为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
1条答案
按热度按时间nbnkbykc1#
您忘记在查询中写入列名。
成功,
而不是,