Discussion:
Java DB embedded problem
nikolaos
2014-10-05 12:08:43 UTC
Permalink
I want to use an embedded java db in my application .
Here is what i have done :

Java DB right click -> properties
Java db installation : C:\Program Files\Java\jdk1.8.0_20\db
Database location : C:\Users\...\.netbeans-derby


Services -> Drivers -> right click -> new driver
Driver File : C:\glassfish4\javadb\lib\derby.jar
Driver Class :org.apache.derby.jdbc.EmbeddedDriver
Name :Java DB (Embedded)

Then right click the new driver choose Connect using :
Java DB (Embedded)
Database : suppliers;create=true
username : admin
pwd : admin

JDBC url :jdbc:derby:


Test connection was succesfull

next choose App scema and finish.

the database node appears with jdbc:derby:suppliers;create=true; [admin on APP]


i created a table 'supplier'

put some columns and tried to make a connection from my application


Code:

with the following code
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Dbconnection {
{

}
public static void main(String args [])
{
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
Connection con= DriverManager.getConnection("jdbc:derby:suppliers;create=true");

PreparedStatement stmt=con.prepareStatement("select * from SUPPLIER");
ResultSet rs=stmt.executeQuery();

} catch (SQLException err) {
System.out.println(err.getMessage()+ "No matching word in database");
} catch (ClassNotFoundException ex) {
Logger.getLogger(Dbconnection.class.getName()).log(Level.SEVERE, null, ex);
}
}
}



result
run:
Table/View 'SUPPLIER' does not exist.No matching word in database
BUILD SUCCESSFUL (total time: 1 second)


i also cannot locate the database anywhere.
Shouldn't it be in C:\Users\...\.netbeans-derby

what do i do wrong?
Ricardo Palomares Martínez
2014-10-06 19:13:00 UTC
Permalink
Post by nikolaos
I want to use an embedded java db in my application .
(...)
Test connection was succesfull
next choose App scema and finish.
(...)
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
Connection con= DriverManager.getConnection("jdbc:derby:suppliers;create=true");
PreparedStatement stmt=con.prepareStatement("select * from SUPPLIER");
Try "select * from APP.SUPPLIER" instead.
Post by nikolaos
result
Table/View 'SUPPLIER' does not exist.No matching word in database
BUILD SUCCESSFUL (total time: 1 second)
i also cannot locate the database anywhere.
Shouldn't it be in C:\Users\...\.netbeans-derby
It should be there, in a subdirectory called "suppliers".

HTH
nikolaos
2014-10-21 12:52:07 UTC
Permalink
Although this post comes a little late (i had forgotten it) , it might help someone with the same problem.
I did everything from the beginning and put all the necessary screenshots in the attachment file.
Loading...