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.
您必须将结果集推进到第一个条目,如下所示:
while(res.next()){System.out.println(res.getString("naziv"));}
查看您的代码,甚至不打印预期的错误,catch块为空,因此打印此异常,您将得到答案。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.