0

I have a database called 'airplane' inside which there is a table named 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

1 Answer 1

1

You forgot to write column names in your query.

Make it,

SELECT * FROM timetable where fromcity=?"

instead of,

SELECT FROM timetable where fromcity=?"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.