You have specified JDBC_DRIVER to

*org.apache.derby.jdbc.ClientDriver ** static final String
JDBC_DRIVER="org.apache.derby.jdbc.ClientDriver";*

You need to include jar file with above class to your class path.


On Wed, Nov 20, 2013 at 7:54 PM, Karthigai Priya Govindarajan <
[email protected]> wrote:

> I am trying to execute the following JDBC pgm. I am using JavaDB .
>
> *package employeedet;*
> *import java.sql.*;*
> *import java.io.*;*
>
> */***
> * **
> * * @author Jayvardhan*
> * */*
> *public class EmployeeDet {*
>
> *    /***
> *     * @param args the command line arguments*
> *     */*
>
> *     //JDBC_DRIVER name and URL*
> *     static final String
> JDBC_DRIVER="org.apache.derby.jdbc.ClientDriver";*
> *     static final String DBURL="jdbc:derby://localhost:1527/Employee";*
>
> *     //Database Credentials*
> *     static final String username="emp";*
> *     static final String password="emp";*
>
> *    public static void main(String[] args) {*
>
> *        Connection con=null;*
> *        Statement stmt=null;*
>
> *        try{*
> *            //Register JDBC driver*
> *            System.out.println("Inside try block");*
> *            Class.forName("org.apache.derby.jdbc.ClientDriver");*
> *            System.out.println("JDBC driver registered...");*
>
> *            //Open a connection*
> *            System.out.println("Connecting to the database....");*
> *            con=DriverManager.getConnection(DBURL,username,password);*
>
> *            //Execute a Query*
> *            System.out.println("Creating the statement");*
> *            stmt=con.createStatement();*
> *            String sql;*
> *            sql="select empid,firstname,lastname,age from EMPDETAILS ";*
> *            ResultSet rs=stmt.executeQuery(sql);*
>
> *            //Extract data from result set*
> *            while(rs.next()){*
> *                int id=rs.getInt("empid");*
> *                String first=rs.getString("firstname");*
> *                String last=rs.getString("lastname");*
> *                int agep=rs.getInt("age");*
>
> *                //Display values*
> *                System.out.println("--------------------------------");*
> *                System.out.println("Employee ID :"+id);*
> *                System.out.println("Age         :"+agep);*
> *                System.out.println("First Name  :"+first);*
> *                System.out.println("Last Name   :"+last);*
> *            }*
>
> *            //Clean-up*
> *            rs.close();*
> *            stmt.close();*
> *            con.close();*
> *        }*
> *        catch(ClassNotFoundException e){*
> *            e.printStackTrace();*
> *        }*
> *        catch(SQLException se){*
> *            //Handle SQL error*
> *            se.printStackTrace();*
> *        }*
> *        finally{*
> *            System.out.println("Selection operation successful");*
> *        }*
> *    }*
> *}*
>
>
> When i execute i get the following output :
>
> *Inside try block*
> *java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver*
> *Selection operation successful*
> * at java.net.URLClassLoader$1.run(URLClassLoader.java:366)*
> * at java.net.URLClassLoader$1.run(URLClassLoader.java:355)*
> * at java.security.AccessController.doPrivileged(Native Method)*
> * at java.net.URLClassLoader.findClass(URLClassLoader.java:354)*
> * at java.lang.ClassLoader.loadClass(ClassLoader.java:424)*
> * at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)*
> * at java.lang.ClassLoader.loadClass(ClassLoader.java:357)*
> * at java.lang.Class.forName0(Native Method)*
> * at java.lang.Class.forName(Class.java:190)*
> * at employeedet.EmployeeDet.main(EmployeeDet.java:35)*
> *BUILD SUCCESSFUL (total time: 0 seconds)*
>
> This happens for all the pgms. that i use JavaDB. How do i fix it?
>
>  --
> You received this message because you are subscribed to the Google Groups
> "JPassion.com: Web Programming Basics" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> Visit this group at http://groups.google.com/group/jpassion_web.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"JPassion.com: Web Programming Basics" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at http://groups.google.com/group/jpassion_web.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to