NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
JosieH
Joined: 13 Apr 2011 Posts: 2
|
Posted: Thu Apr 14, 2011 12:36 am Post subject: Trouble Connecting to JavaDB - Desparately need HELP |
|
|
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
|
Posted: Tue May 31, 2011 1:44 pm Post subject: create tables |
|
|
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
|
Posted: Tue May 31, 2011 1:57 pm Post subject: create=true |
|
|
| 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
|
Posted: Tue May 31, 2011 11:45 pm Post subject: Worked it out |
|
|
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 |
|
 |
|
|
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
|
|