java jdbc程序从表中获取特定行时抛出sql语法错误

xkrw2x1b  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(280)

我有一个名为“飞机”的数据库,里面有一个名为“时间表”的表。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
nbnkbykc

nbnkbykc1#

您忘记在查询中写入列名。
成功,

SELECT * FROM timetable where fromcity=?"

而不是,

SELECT FROM timetable where fromcity=?"

相关问题