NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Trouble Connecting to JavaDB - Desparately need HELP

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
JosieH



Joined: 13 Apr 2011
Posts: 2

PostPosted: Thu Apr 14, 2011 12:36 am    Post subject: Trouble Connecting to JavaDB - Desparately need HELP Reply with quote

I'm doing a university project where I have to write an application with a backend database. I'm trying to use JavaDB.

I've created a simple JavaDB database in Netbeans. I've got the driver loaded but it's not connecting to the database.

I have the following code (GP_Demo, is the name of the database):


public static void main(String[] args) {
try {
// Load the JDBC driver
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
System.out.println("Driver loaded");
} catch (Exception e) {
throw new RuntimeException("Could not load JavaDB JDBC driver");
}

try {
// Establish a connection
Connection con = DriverManager.getConnection("jdbc:derby:GP_Demo");
System.out.println("Database connected");

// Create a statement
Statement s = con.createStatement();

//Execute a statement
ResultSet rs = s.executeQuery("SELECT * FROM Students");

// Iterate through the result and print the student names
while(rs.next())
System.out.println(rs.getInt(1) + "\t"
+ rs.getString(2) + "\t"
+ rs.getString(3));

// Close the connection
con.close();
} catch(Exception e){
throw new RuntimeException("Could not connect to GP_Demo");
}
Back to top
ceyezumma



Joined: 02 Feb 2009
Posts: 122

PostPosted: Tue May 31, 2011 1:44 pm    Post subject: create tables Reply with quote

I have created a derby db and connected.
I'm not sure what you have though.
Have you created tables?
and are you using xml or a properties sheet to get dbName etc?
Back to top
ceyezumma



Joined: 02 Feb 2009
Posts: 122

PostPosted: Tue May 31, 2011 1:57 pm    Post subject: create=true Reply with quote

I couldn't create a embedded database at one time too, but I just had to add "create=true" this may be your simple solution to.
Back to top
JosieH



Joined: 13 Apr 2011
Posts: 2

PostPosted: Tue May 31, 2011 11:45 pm    Post subject: Worked it out Reply with quote

Hi
Sorry, I forgot I'd posted this. I worked it out. Turns out I'd missed the whole bit about the .jar libraries.

But thanks anyways
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo