Results 1 to 2 of 2
  1. #1
    kasiforjava is offline Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Exclamation Runtime Exceptions for JDBC program using Derby Client in Netbeans

    XML Code:
    I was trying to connect to a simple database through netbeans using the Type 4 connectivity ( Derby ) . Although i could successfully compile the following code for it :
    
    [b]Source Code [/b]
    [code=java]
    package javaapplication2;
    import java.sql.*;
    public class JavaApplication2 {
    
      
        public static void main(String[] args) throws ClassNotFoundException, SQLException {
            String name;
            int id;
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/Sample1");
            Statement stmt=con.createStatement();
            ResultSet rs=stmt.executeQuery("Select *from Kasi");
            while(rs.next())
            {
                id=rs.getInt(1);
                name=rs.getString(2);
                System.out.print("\nId="+id+"\nName="+name);
            }
            // TODO code application logic here
        }
    }
    
    [/code]
    I am getting the following Exception :
    
    [b]Exception [/b]
    Exception in thread "main" java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: 
    connect.
    	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:579)
    	at java.sql.DriverManager.getConnection(DriverManager.java:243)
    	at javaapplication2.JavaApplication2.main(JavaApplication2.java:22)
    Caused by: org.apache.derby.client.am.DisconnectException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
    	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)
    	... 4 more
    Caused by: java.net.ConnectException: Connection refused: connect
    	at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
    	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
    	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
    	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
    	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    	at java.net.Socket.connect(Socket.java:579)
    	at java.net.Socket.connect(Socket.java:528)
    	at java.net.Socket.<init>(Socket.java:425)
    	at java.net.Socket.<init>(Socket.java:208)
    	at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:271)
    	at org.apache.derby.client.net.OpenSocketAction.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	... 10 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 3 seconds)
    even though i've imported .jar file for the Derby client required , i couldn't overcome this exception .

    So it would be really great if you could Kindly help me to overcome this Excception to run my first JDBC Program :)

    Thanks in Advance

    Regards,
    Kasiraj

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Runtime Exceptions for JDBC program using Derby Client in Netbeans

    It's that port.
    Something is stopping you accessing that port number (hence the root exception when it is trying to open a socket).
    No idea what it would be.

Similar Threads

  1. Replies: 0
    Last Post: 06-27-2011, 04:39 PM
  2. Runtime/Compile Time Exceptions
    By suresh.sa in forum New To Java
    Replies: 1
    Last Post: 10-18-2010, 11:32 AM
  3. Using Derby Database in Netbeans
    By DavidG24 in forum New To Java
    Replies: 1
    Last Post: 09-14-2009, 01:29 PM
  4. TCPIP Client (handling specific exceptions)
    By ravian in forum Networking
    Replies: 3
    Last Post: 11-29-2007, 09:56 AM
  5. Runtime Exceptions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-12-2007, 10:31 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •