You are getting a classic class not found exception. Do you have driver jar configured. Search for the stack trace error on google. That's always a good start.
Thanks G Sent from my iPhone > On Nov 20, 2013, at 8:30 AM, Karthigai Priya Govindarajan > <[email protected]> wrote: > > Hi > > I am trying to execute the following JDBC pgm. using JavaDb. > > > JDBC_DRIVER="org.apache.derby.jdbc.ClientDriver"; > DBURL="jdbc:derby://localhost:1527/Employee"; > > > Program > --------------- > 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 | SQLException e){ > e.printStackTrace(); > } > finally{ > System.out.println("Selection operation successful"); > } > } > } > > When i execute the program i get the following error : > > 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) > > > I get the above error for all the programs using JavaDB. Could you help me to > fix it? > > > -- > You received this message because you are subscribed to the Google Groups > "JPassion.com: Java Programming" 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_java. > 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: Java Programming" 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_java. For more options, visit https://groups.google.com/groups/opt_out.
