0

I'm trying to connect to embedded database Java DB from NetBeans 7.1.

this is what I tried:

    try{
    String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    String url = "jdbc:derby:market; create=true";
    String db = "/artikli";
    String user = "wolf";
    String pass = "wolf";
    String query = "SELECT * FROM artikli";
    Connection conn = null;

        Class.forName(driver);
        conn = DriverManager.getConnection(url + db, user, pass);
        java.sql.Statement stmt = conn.createStatement();
        ResultSet res = stmt.executeQuery(query); 

        System.out.println(res.getString("naziv")); // naziv = column name


        res.close();

    }catch(Exception e){

    }

My question is how to get data and print, or populate JTable with it, and is this connection good, thanks? thank you in advance.

4
  • Please post the error you got. Commented Mar 23, 2012 at 14:20
  • I'm trying to connect to embedded database Java DB from NetBeans 7.1 -- I'm not familiar with Netbeans, but try looking in the menus. Perhaps you have a menu like "Databases" where you can select "Connect...". HTH. Commented Mar 23, 2012 at 14:24
  • I don't have error, just I don't get anything printed. I have already populated database table. My question is how to get data and print, or populate JTable with it, and is this connection good, thanks? Commented Mar 23, 2012 at 14:25
  • @Wolf87 - You do have an error, but your catch clause is swallowing it. As Oleg suggested, print the exception so you can see it... Commented Mar 24, 2012 at 0:57

2 Answers 2

1

You must advance the result set to the first entry, like this:

while(res.next()){System.out.println(res.getString("naziv"));}
Sign up to request clarification or add additional context in comments.

1 Comment

Complementing: more info about JDBC in docs.oracle.com/javase/tutorial/jdbc/index.html
0

look at your code, you even don't print expected errors, your catch block is empty, so print this exception and you will get the answer.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.