i am create a java project and i want to use derby data base and and i am configured database and create database with the name of /home/user/TestDB
and create a table user
and insert 3 to 4 values into it and write a code to get the data from database but when i connect dada base i got connection refuse error, i am use
DB URL : jdbc:derby://localhost:1527/home/user/TestDB
error logs :
java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at test.derby.util.DerbyUtil.getConnecation(DerbyUtil.java:34)
at test.derby.dao.TestDAO.getData(TestDAO.java:20)
at test.derby.dao.TestDAO.main(TestDAO.java:39)
Caused by: org.apache.derby.client.am.DisconnectException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.
at org.apache.derby.client.net.NetAgent.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection.newAgent_(Unknown Source)
at org.apache.derby.client.am.Connection.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)
at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source)
... 6 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
i think you are not start your derver server
in specific port which you are using. you need to start server using below command on localhost with default port 1527
startNetworkServer -h 0.0.0.0
if you want to change the port you can use below command :
startNetworkServer -p 3301 // new port number
for more you can refer below link;
http://www.vogella.com/tutorials/ApacheDerby/article.html
may be this error occur because of following reasons:
1) Firewall is not permitted for host-port combination
2) Client and Server, either or both of them are not in the network.
3) The server is running but not listening on the port, a client is trying to connect.
4) Server is not running.
5) Incorrect protocol in Connection String
This error occurs just because your database is not connected.
NETBEANS
Go to Services>Database>Java DB>(right click) After that simply right click on your database and connect database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With