Processing with JavaDB?
in
Programming Questions
•
2 years ago
Hi Guys,
I'm working on a project where I need to connect to a JavaDB (Apache Derby) database and query data from it, and I'm wondering if anyone here has seen a tutorial on how to connect Processing to JavaDB? Or better yet, knows how to integrate JavaDB into Processing..?
I've done the following, but I kept getting the 'driver not found' error... does anyone has any ideas or suggestions? Thanks a bunch in advance!
niM_xaM
I'm working on a project where I need to connect to a JavaDB (Apache Derby) database and query data from it, and I'm wondering if anyone here has seen a tutorial on how to connect Processing to JavaDB? Or better yet, knows how to integrate JavaDB into Processing..?
I've done the following, but I kept getting the 'driver not found' error... does anyone has any ideas or suggestions? Thanks a bunch in advance!
niM_xaM
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
Connection conn;
PreparedStatement psInsert = null;
PreparedStatement psUpdate = null;
Statement s = null;
ResultSet rs = null;
void setup() {
loadDriver();
try {
conn = DriverManager.getConnection( "jdbc:derby:YMLD;" );
println( "Connected to Database!" );
} catch( SQLException sqle ) {
printSQLException( sqle );
}
} // end setup()
void printSQLException( SQLException e ) {
while( e != null ) {
println( "----- SQLException -----" );
println( " SQL State: " + e.getSQLState() );
println( " Error Code: " + e.getErrorCode() );
println( " Message: " + e.getMessage() );
//e.printStackTrace( System.err );
e = e.getNextException();
} // end while
} // end printSQLException
void loadDriver() {
try {
Class.forName( "org.apache.derby.jdbc.EmbeddedDriver" ).newInstance();
} catch (ClassNotFoundException cnfe ) {
System.err.println( "\nUnable to load the JDBC driver " + "org.apache.derby.jdbc.EmbeddedDriver" );
System.err.println( "Please check your CLASSPATH." );
cnfe.printStackTrace( System.err );
} catch ( InstantiationException ie ) {
System.err.println( "\nUnable to instantiate the JDBC driver " + "org.apache.derby.jdbc.EmbeddedDriver" );
ie.printStackTrace( System.err );
} catch( IllegalAccessException iae ) {
System.err.println( "\nNot allowed to access the JDBC driver " + "org.apache.derby.jdbc.EmbeddedDriver" );
iae.printStackTrace(System.err);
}
} // end loadDriver()
1
