Guest User

Untitled

a guest
Feb 11th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. public class DBConnections{
  2.  
  3. private static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
  4. private static String JDBC_URL;
  5. private static Statement st;
  6. private static Connection con;
  7.  
  8. public DBConnections(Statement statement) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
  9. Class.forName(DRIVER).newInstance();
  10. con = DriverManager.getConnection(connectionUrl());
  11.  
  12. //This is where my problem is-------------------
  13. this.st = statement
  14. //----------------------------------------------
  15. con.close();
  16. }
  17.  
  18. private static final String connectionUrl() {
  19. JDBC_URL = "jdbc:derby:C:\Users\Banan\eclipse-workspace\Java-Flix\lib\MyDB;USER = JavaFlix; password = 123";
  20. return JDBC_URL;
  21. }
  22.  
  23. public static Statement selectQueryDB () throws SQLException {
  24. st = con.createStatement();
  25. ResultSet rs = st.executeQuery("select * from JAVAFLIX.MOVIES");
  26.  
  27. while(rs.next()) { String movieName = rs.getString("MOVIE_NAME");
  28. String catergory = rs.getString("CATERGORY");
  29. String actors = rs.getString("ACTORS");
  30. String description = rs.getString("DESCRIPTION");
  31. String ratingImgUrl = rs.getString("RATING_IMG");
  32. String movieImgUrl = rs.getString("MOVIE_IMG");
  33. }
  34. rs.close();
  35. return st;
  36. }
  37. }
  38.  
  39. public class Main {
  40.  
  41. public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
  42.  
  43. Statement st = DBConnections.selectQueryDB();
  44. DBConnections d = new DBConnections(st);
  45. }
  46. }
Add Comment
Please, Sign In to add comment