Following code works until I try to add WHERE to the Query. I have no errors before run but get the errors below. I need the proper syntax or method to specify the row. HELP!!!
Exception in thread "main" java.lang.NullPointerExceptionimport java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class TryThree { public static void main(String args[]) throws SQLException{ Connection con = DriverManager.getConnection ("jdbc:mysql://67.20.123.248:3306/whitebu4_sliditerod" ,"whitebu4_admins" , "***"); String dbClass = "com.mysql.jdbc.Driver"; String Nome = null; String query = ("Select x,y,z FROM xyz WHERE pname='" + Nome + "'"); Object prepareStatement = null; ((PreparedStatement) prepareStatement).setString(1, Nome); try { Class.forName("com.mysql.jdbc.Driver"); Statement st = con.createStatement(); ResultSet rs = st.executeQuery(query); while(rs.next()){ float id = rs.getFloat("x"); float id1 = rs.getFloat("y"); float id2 = rs.getFloat("z"); System.out.print("ID: " + id); System.out.print("id1 " + id1); System.out.print("id2 " + id2); } //end while con.close(); } //end try catch(ClassNotFoundException e) { e.printStackTrace(); } catch(SQLException e) { e.printStackTrace(); } } //end main } //end class
at TryThree.main(TryThree.java:21)