0

How should I solve this issue: if I run my code, and I try to create an instance of DB I get always "

    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at DB.<init>(DB.java:18)
    at FirstConnection.main(FirstConnection.java:4)" exception in eclipse.

My code looks like this:

public class FirstConnection {
    public static void main(String[] args) {
        DB db=new DB();
    }
}

import java.sql.Connection;
public class DB {

    String url = "jdbc:derby:sampleDB";
    String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    String username = "";
    String password = "";

    public DB() {
        Connection con = null;
        try {
            con = DriverManager.getConnection(url);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

I use Java 1.8.0_232 version. my classpath file is:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="lib" path="src/lib/derby.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

and I use derby:db-derby-10.15.2.0-lib and my eclipse is:Version: 2018-12 (4.10.0)

jarlh
  • 42,561
  • 8
  • 45
  • 63
gerg
  • 19
  • 1
  • 6
  • Does this answer your question? [SQLException: No suitable driver found for jdbc:derby://localhost:1527](https://stackoverflow.com/questions/3816015/sqlexception-no-suitable-driver-found-for-jdbcderby-localhost1527) – rkosegi Feb 25 '21 at 17:09
  • 1
    You're missing `derbyshared.jar` and maybe `derbytools.jar`, see [Libraries provided by Derby](https://db.apache.org/derby/docs/10.15/getstart/rgslib46043.html). BTW: This is one of the reasons it is better to use Maven or Gradle to manage your dependencies, then trying to do it yourself. – Mark Rotteveel Feb 25 '21 at 17:13
  • 1
    Related, possibly duplicate: [java.lang.NoClassDefFoundError while connecting to Embedded Derby Database](https://stackoverflow.com/questions/60649262/java-lang-noclassdeffounderror-while-connecting-to-embedded-derby-database) – Mark Rotteveel Feb 25 '21 at 17:17

0 Answers0