db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pranav Aggarwal <pranav.aggar...@altair.com>
Subject NetworkDriver connection issues...
Date Tue, 06 Mar 2007 04:58:01 GMT
Hi,

          I created a simple program in order to access the 
Client/Server model of Derby... but after compiling and running the 
below program, i got the error:

*ERROR*
java derby_connection
java.lang.ClassNotFoundException: org.apache.derby.jdbc.NetworkDriver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:164)
        at derby_connection.connect(derby_connection.java:14)
        at derby_connection.main(derby_connection.java:41)
java.sql.SQLException: No suitable driver
        at java.sql.DriverManager.getConnection(DriverManager.java:545)
        at java.sql.DriverManager.getConnection(DriverManager.java:193)
        at derby_connection.connect(derby_connection.java:21)
        at derby_connection.main(derby_connection.java:41)
Exception in thread "main" java.lang.NullPointerException
        at derby_connection.connect(derby_connection.java:35)
        at derby_connection.main(derby_connection.java:41)

                I checked, the network service as well, and it was 
running....


-----------------------------------------------------------------------------------------
import java.sql.*;
                                                                                         
                                   

class derby_connection
{
        void connect() throws Exception
        {
                String driver="org.apache.derby.jdbc.NetworkDriver";
                String dbName="mydb";
                                                                                         
                                   

                String connectionURL="jdbc:derby://localhost:1527/"+dbName;
                Connection conn=null;
                try
                {
                        Class.forName(driver).newInstance();
                }catch(java.lang.ClassNotFoundException e)
                {
                        e.printStackTrace();
                }
                try
                {
                        conn=DriverManager.getConnection(connectionURL);
                        System.out.println("Connection established!!!");
                        Statement st=conn.createStatement();
                        ResultSet rs=st.executeQuery("Select * from 
applicationdb");
                        while(rs.next())
                        {
                                String first=rs.getString(1);
                                String last=rs.getString(2);
                                System.out.println("Name: "+first+" "+last);
                        }
                        rs.close();
                }
                catch(Throwable e)
                {e.printStackTrace();}
                finally {conn.close();}
                                                                                         
                                   

        }//end of connect()
        public static void main(String args[]) throws Exception
        {
                derby_connection dc=new derby_connection();
                dc.connect();
        }
}//end of class
-----------------------------------------------------------------------------------------------------------------------------------------------

could any one plz tell me where I am going wrong...

I was able to connect the database using ij as
ij> connect 'jdbc:derby://localhost:1527/mydb';
ij>

-- 
Thanks & Regards,
Pranav Aggarwal
(M) +91 - 99802 19982
(O) +91 - 80 - 66294500 (Ext. 4896)
Altair Engineering
http://www.altair-india.com/


Mime
View raw message