Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DBConnections{
- private static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
- private static String JDBC_URL;
- private static Statement st;
- private static Connection con;
- public DBConnections(Statement statement) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
- Class.forName(DRIVER).newInstance();
- con = DriverManager.getConnection(connectionUrl());
- //This is where my problem is-------------------
- this.st = statement
- //----------------------------------------------
- con.close();
- }
- private static final String connectionUrl() {
- JDBC_URL = "jdbc:derby:C:\Users\Banan\eclipse-workspace\Java-Flix\lib\MyDB;USER = JavaFlix; password = 123";
- return JDBC_URL;
- }
- public static Statement selectQueryDB () throws SQLException {
- st = con.createStatement();
- ResultSet rs = st.executeQuery("select * from JAVAFLIX.MOVIES");
- while(rs.next()) { String movieName = rs.getString("MOVIE_NAME");
- String catergory = rs.getString("CATERGORY");
- String actors = rs.getString("ACTORS");
- String description = rs.getString("DESCRIPTION");
- String ratingImgUrl = rs.getString("RATING_IMG");
- String movieImgUrl = rs.getString("MOVIE_IMG");
- }
- rs.close();
- return st;
- }
- }
- public class Main {
- public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
- Statement st = DBConnections.selectQueryDB();
- DBConnections d = new DBConnections(st);
- }
- }
Add Comment
Please, Sign In to add comment