Hallo an alle!
Ich benutze JBuilder 2007 und J2SE 1.5.
Ich habe derby soweit als Library integriert und wenn ich auf „Run“ gehe läuft es auch prima.
Untenstehender Quellcode verwende ich dabei.
Jedoch: Mache ich über Export ein jar-File daraus namens test.jar und öffne es in der Konsole mit
java -jar test.jar so erscheint folgendes:
"
/Users/testName
ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
Make sure your CLASSPATH variable contains %DERBY_HOME%\lib\derby.jar (${DERBY_HOME}/lib/derby.jar).
Trying to connect to jdbc:derby:jdbcDemoDB1;create=true
—SQLException Caught—
SQLState: 08001
Severity: 0
Message: No suitable driver
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at imageo.model.DerbyTest.main(DerbyTest.java:25)
"
Im test.jar-File ist kein derby.jat integriert. Das sehe wegen der geringen Dateigröße. Die Datei derby.jar
ist bereits 2 MB groß, dann müsste das test.jar ja größer als 2MB sein, es ist aber nur ein paar KB.
Was muss ich machen, damit dies ins test.jar eingebunden wird?
Danke + Gruß PHANTOM
import java.sql.*;
public class DerbyTest {
public static void main(String[] args) {
String driver = „org.apache.derby.jdbc.EmbeddedDriver“;
String dbName=„jdbcDemoDB1“;
String connectionURL = „jdbc:derby:“ + dbName + „;create=true“;
Connection conn = null;
System.out.println(System.getProperty(„user.home“, „.“));
try {
Class.forName(driver);
System.out.println(driver + " loaded.");
} catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: „);
System.err.println(e.getMessage());
System.out.println(“\n Make sure your CLASSPATH variable " +
„contains %DERBY_HOME%\lib\derby.jar (${DERBY_HOME}/lib/derby.jar). \n“);
}
try {
System.out.println("Trying to connect to " + connectionURL);
conn = DriverManager.getConnection(connectionURL);
System.out.println("Connected to database " + connectionURL);
conn.close();
System.out.println(„Closed connection“);
boolean gotSQLExc = false;
try {
DriverManager.getConnection(„jdbc:derby:;shutdown=true“);
} catch (SQLException se) {
if ( se.getSQLState().equals(„XJ015“) ) {
gotSQLExc = true;
}
}
if (!gotSQLExc) {
System.out.println(„Database did not shut down normally“);
} else {
System.out.println(„Database shut down normally“);
}
System.gc();
Thread.sleep(1500);
} catch (Throwable e) {
errorPrint(e);
System.exit(1);
}
connectionURL = „jdbc:derby:“ + dbName;
try {
Class.forName(driver).newInstance();
System.out.println(driver + " loaded.");
} catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: „);
System.err.println(e.getMessage());
System.out.println(“\n Make sure your CLASSPATH variable " +
„contains %DERBY_HOME%\lib\derby.jar (${DERBY_HOME}/lib/derby.jar). \n“);
} catch(java.lang.IllegalAccessException e) {
System.err.print("IllegalAccessException: ");
System.err.println(e.getMessage());
} catch(java.lang.InstantiationException e) {
System.err.print("InstantiationException: ");
System.err.println(e.getMessage());
}
try {
System.out.println("Trying to connect to " + connectionURL);
conn = DriverManager.getConnection(connectionURL);
System.out.println("Connected to database " + dbName);
conn.close();
System.out.println(„Closed connection“);
boolean gotSQLExc = false;
try {
DriverManager.getConnection(„jdbc:derby:;shutdown=true“);
} catch (SQLException se) {
if ( se.getSQLState().equals(„XJ015“) ) {
gotSQLExc = true;
}
}
if (!gotSQLExc) {
System.out.println(„Database did not shut down normally“);
} else {
System.out.println(„Database shut down normally“);
}
} catch (Throwable e) {
errorPrint(e);
System.exit(1);
}
}
static void errorPrint(Throwable e) {
if (e instanceof SQLException)
SQLExceptionPrint((SQLException)e);
else {
System.out.println(„A non-SQL error occurred.“);
e.printStackTrace();
}
}
static void SQLExceptionPrint(SQLException sqle) {
while (sqle != null) {
System.out.println("\n—SQLException Caught—\n");
System.out.println("SQLState: " + (sqle).getSQLState());
System.out.println("Severity: " + (sqle).getErrorCode());
System.out.println("Message: " + (sqle).getMessage());
sqle.printStackTrace();
sqle = sqle.getNextException();
}
}
}