2

I use Netbeans, doing a java app. I created a class ConnectDB for db connetion using Java DB in netbeans. i started the server and ten conneted to db. when i run the file it produce

java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver @ 25 line

and

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/Libraryprj;create=true

@30 th line of code

the code is below

package Lms;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author JOJO
 */
public class ConnectDB {
  static Connection conn;

  public static void main(String[] args) {
    String driver = "org.apache.derby.jdbc.ClientDriver";
    String connectionURL = "jdbc:derby://localhost:1527/Libraryprj;create=true";
    String createString = "CREATE TABLE Employee (NAME VARCHAR(32) NOT NULL, ADDRESS VARCHAR(50) NOT NULL)";
    try {
      Class.forName(driver);
    } catch (java.lang.ClassNotFoundException e) {
      e.printStackTrace();
    }
    try {
      conn = DriverManager.getConnection(connectionURL);
      Statement stmt = (Statement) conn.createStatement();
      stmt.executeUpdate(createString);

      PreparedStatement psInsert = conn.prepareStatement("insert into Employee values (?,?)");

      psInsert.setString(1, args[0]);
      psInsert.setString(2, args[1]);

      psInsert.executeUpdate();

      Statement stmt2 = (Statement) conn.createStatement();
      ResultSet rs = stmt2.executeQuery("select * from Employee");
      int num = 0;
      while (rs.next()) {
        System.out.println(++num + ": Name: " + rs.getString(1) + "\n Address" + rs.getString(2));
      }
      rs.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
1
  • have you imported derby related jar libraries? Commented Jul 18, 2012 at 13:45

2 Answers 2

5

get this library
http://repo.maven.apache.org/maven2/org/apache/derby/derbyclient/10.9.1.0/derbyclient-10.9.1.0.jar

and copy it to Derby's libs folder.

Sign up to request clarification or add additional context in comments.

2 Comments

Derby's lib folder or My project lib folder @ilya
Derby's lib folder OR your folder+add to classpath in META-INF/MANIFEST.MF
2

If you use Tomcat download derbyclient.jar from here . And copy the jar file to Tomcat's lib folder.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.