Advertisement
Guest User

Untitled

a guest
May 19th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. error: cannot find symbol PreparedStatement st = conn.prepareStatement("SELECT * FROM table WHERE name = ?");
  2. symbol: variable conn
  3. location: class splitString
  4.  
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.PreparedStatement;
  8. import java.sql.ResultSet;
  9.  
  10. class splitString{
  11. public static void main(String[] args){
  12.  
  13. //Connect to database
  14. try
  15. {
  16. Class.forName("org.postgresql.Driver");
  17. Connection con=DriverManager.getConnection("jdbc:postgresql://localhost/database", "postgres", "pswd");
  18. if(con != null)
  19. System.out.println("Connection Successful!");
  20. }
  21. catch(Exception ee)
  22. {
  23. ee.printStackTrace();
  24. }
  25.  
  26. String word = "Apples";
  27. PreparedStatement st = conn.prepareStatement("SELECT * FROM table WHERE name = ?");
  28. st.setString(1, word);
  29. ResultSet rs = st.executeQuery();
  30.  
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement