NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
mn1247
Joined: 04 Jan 2011 Posts: 64
|
Posted: Tue Apr 12, 2011 2:20 pm Post subject: Code to connect to database not working |
|
|
I have the following routine that I am trying to use to connect to my database:
| Code: | public static void connectToDatabase() {
String host = "jdbc:derby://localhost:1527/Test1";
String uName = "APP";
String uPass = "APP";
try {
Connection con = DriverManager.getConnection(host, uName, uPass);
} catch (Exception e) {
Logger.getLogger(EUtil.class.getName()).log(Level.SEVERE, null, e);
}
} |
But, I still have to go to "Services" and connect the database manually when I start NB. How can I make this fully automatic?
Thanks
Eric |
|
| Back to top |
|
 |
markwade
Joined: 04 Dec 2010 Posts: 140
|
Posted: Wed Apr 13, 2011 3:34 am Post subject: Code to connect to database not working |
|
|
On Apr 12, 2011, at 10:20 AM, mn1247 wrote:
| Quote: | I have the following routine that I am trying to use to connect to
my database:
Code:
public static void connectToDatabase() {
String host = "jdbc:derby://localhost:1527/Test1";
String uName = "APP";
String uPass = "APP";
try {
Connection con = DriverManager.getConnection(host, uName,
uPass);
} catch (Exception e) {
Logger.getLogger(EUtil.class.getName()).log(Level.SEVERE,
null, e);
}
}
But, I still have to go to "Services" and connect the database
manually when I start NB. How can I make this fully automatic?
Thanks
Eric
|
You aren't loading the driver:
Class.forName("org.apache.derby.jdbc.ClientDriver");
or
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
-- Mark |
|
| Back to top |
|
 |
jupok3
Joined: 13 Apr 2011 Posts: 1
|
Posted: Wed Apr 13, 2011 8:16 am Post subject: |
|
|
| forum very interesting |
|
| Back to top |
|
 |
mn1247
Joined: 04 Jan 2011 Posts: 64
|
Posted: Wed Apr 13, 2011 1:32 pm Post subject: |
|
|
Thanks for the reply.
I tried
| Code: | | Class.forName("org.apache.derby.jdbc.ClientDriver"); |
But it errors with
| Code: | | java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused. |
Where am I going wrong?
Eric |
|
| Back to top |
|
 |
markwade
Joined: 04 Dec 2010 Posts: 140
|
Posted: Wed Apr 13, 2011 4:38 pm Post subject: |
|
|
| mn1247 wrote: | Thanks for the reply.
I tried
| Code: | | Class.forName("org.apache.derby.jdbc.ClientDriver"); |
But it errors with
| Code: | | java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused. |
Where am I going wrong?
Eric |
You have to start derby.
Run startNetworkServer (there is a Windows .bat version) in the derby installation directory/bin.
In NetBeans use the services tab. If you have the project setup to use glassfish, netbeans should start derby for you.
-- Mark |
|
| Back to top |
|
 |
javydreamercsw
Joined: 22 Jun 2009 Posts: 456
|
|
| 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
|
|