Results 1 to 9 of 9
Thread: derby DB problem
- 05-16-2010, 07:49 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 12
- Rep Power
- 0
derby DB problem
Ive lately tried doing some stuff with Java data bases. im using derby.
i created a data base through NB and added a testing table.
i tried to create a connection to that DB through java code- but evrey time when it reaches the connection statement it throws an exception:
the weird thing is that if i connect to the db via the services window and then disconnect, before i start the java code- it works.Java Code:java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
i did add the derby and derbyclient jar's to my libraries.
here is some of my code:
does anybody have any idea as to what could be causing this weird problem?Java Code:Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/TestDB","edi123","edi123"); java.sql.Statement stmt = con.createStatement(); try { ResultSet rs = stmt.executeQuery("SELECT * FROM App.TestCreate"); while (rs.next()) { String n = rs.getString("Name"); String p = rs.getString ("UserName"); System.out.println(n + " " + p); }} catch(Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); System.exit(0); } }}
thanks
EdiLast edited by edi.gotieb; 05-16-2010 at 07:52 PM.
- 05-16-2010, 08:06 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
What happens when you try to open a connection to "jdbc:derby:<your database>"? i.e. you are using an embedded driver so there is no use to specifying a host and port number.
kind regards,
Jos
- 05-16-2010, 08:49 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 12
- Rep Power
- 0
- 05-16-2010, 08:52 PM #4
Member
- Join Date
- Apr 2010
- Posts
- 12
- Rep Power
- 0
i just tried to run with your suggestion and it worked!
thanks a lot!
i'de be glad if you can elaborate on what an embedded driver means?
thanks
Edi
- 05-16-2010, 08:52 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 05-16-2010, 08:54 PM #6
Member
- Join Date
- Apr 2010
- Posts
- 12
- Rep Power
- 0
i did! and it works! thanks very much.
- 05-16-2010, 09:06 PM #7
Member
- Join Date
- Apr 2010
- Posts
- 12
- Rep Power
- 0
hi-
im having a different issue now.
when i creat a database through NB it automatically sets the URL and driver-
to the client driver- and the URL with the host and port.
NB manages to connect to the db when i just leave it but when i change the properties to the ones you showed me (i.e no host and port+ embeeded driver)
NB is unable to connect to the DB.
other then that- what effect does the driver choosing have on the db?
i mean: the data base is the same no matter what driver i use?
+ why is it unable to connect via the IDE but is able in the exact same fashion through the java code?
thanks
Edi
- 05-16-2010, 09:11 PM #8
Member
- Join Date
- Apr 2010
- Posts
- 12
- Rep Power
- 0
i solved the problem but would like answers to the questions about databases. :):D
- 05-17-2010, 12:45 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
This is ripped straight from the JavaDB documents (you have them installed too if you have Java 1.6 SE installed):
for the other driver this is what those docs have to say:
Originally Posted by JavDB docs
I don't know NetBeans so I don't know why it failed to configure your database driver.Client/server environment
A client/server environment is an environment in which multiple applications connect to Derby over the network.
Derby runs embedded in a server framework that allows multiple network connections. (The framework itself starts an instance of Derby and runs in an embedded environment. However, the client applications do not run in the embedded environment.)
You can also embed Derby in any Java server framework.
See the Java DB Server and Administration Guide for more information on how to run Derby on a server.
kind regards,
Jos
Similar Threads
-
Problem Connecting JavaDB (Derby) DB in other PC
By Blaine in forum JDBCReplies: 1Last Post: 05-11-2010, 10:31 AM -
need some derby tips:
By kulangotski in forum Advanced JavaReplies: 4Last Post: 03-09-2009, 05:09 PM -
procedures in derby
By suhaib1thariq in forum JDBCReplies: 0Last Post: 01-31-2009, 05:39 PM -
using if in derby
By suhaib1thariq in forum JDBCReplies: 0Last Post: 01-25-2009, 04:46 AM -
Is there a problem with Derby?
By orion_mcl in forum Advanced JavaReplies: 0Last Post: 08-10-2007, 04:35 AM


LinkBack URL
About LinkBacks


Bookmarks