Connect to Oracle using thin driver
843854Aug 2 2004 — edited Aug 3 2004Hi,
Iam copy-paste a "very simple aplication" that connect to oracle database 8.1.7.0. I am using the Netbeans IDE 3.6.
i can compile without error, but to the execute say "Failed to load current Driver", same the the try-catch block.
I load the driver using de runtime database driver in the Netbean Ide and cant load and test the connection withoit probelm
Do you can say me that is wrong.
Thank for advance
Pedro Emilio
The source code is
import java.sql.*;
import java.util.*;
public class Create4JData
{
static String[] SQLData =
{
"(1, 'John', 'Mon', 1, 'JustJoe')",
"(2, 'JS', 'Mon', 1, 'Cappuccino')",
"(3, 'Marie', 'Mon', 2, 'CaffeMocha')",
"(4, 'Anne', 'Tue', 8, 'Cappuccino')",
"(5, 'Holley', 'Tue', 2, 'MoJava')",
"(6, 'jDuke', 'Tue', 3, 'Cappuccino')",
"(7, 'Marie', 'Wed', 4, 'Espresso')",
"(8, 'JS', 'Wed', 4, 'Latte')",
"(9, 'Alex', 'Thu', 3, 'Cappuccino')",
"(10, 'James', 'Thu', 1, 'Cappuccino')",
"(11, 'jDuke', 'Thu', 4, 'JustJoe')",
"(12, 'JS', 'Fri', 9, 'Espresso')",
"(13, 'John', 'Fri', 3, 'Cappuccino')",
"(14, 'Beth', 'Fri', 2, 'Cappuccino')",
"(15, 'jDuke', 'Fri', 1, 'Latte')"
};
public static void main(String[] args)
{
Connection con = null;
int iRowCount = 0;
Statement stmt = null;
String sDriver="sun.jdbc.odbc.jdbcodbcdriver";
//String sDriver = "oracle.jdbc.driver.OracleDriver";
String sURL =
"jdbc:oracle:thin:@servername:1521:pesp;create=true";
String sUsername = "system";
String sPassword = "manager";
try // Attempt to load the JDBC driver
{ // with newInstance
Class.forName("sun.jdbc.odbc.jdbcodbcdriver");
//.newInstance();
}
catch( Exception e ) // error
{
System.err.println(
"Failed to load current driver.");
return;
} // end catch
try
{
con = DriverManager.getConnection ( sURL,
sUsername,
sPassword);
stmt = con.createStatement();
}
catch ( Exception e)
{
System.err.println( "problems connecting to " +
sURL + ":" );
System.err.println( e.getMessage() );
if( con != null)
{
try { con.close(); }
catch( Exception e2 ) {}
}
return;
} // end catch
// to allow the program to be run more than once,
// attempt to remove the table from the database
try
{
stmt.executeUpdate( "DROP TABLE scott.JJJJData" );
System.out.println(
"Table JJJJData was removed.");
}
catch ( Exception e ) { /* don't care */ }
// execute SQL commands
// to create table and insert data
try
{
stmt.executeUpdate( "CREATE TABLE scott.JJJJData (" +
"Entry INTEGER NOT NULL, " +
"Customer VARCHAR (20) NOT NULL, " +
"DOW VARCHAR (3) NOT NULL, " +
"Cups INTEGER NOT NULL, " +
"Type VARCHAR (10) NOT NULL," +
"PRIMARY KEY( Entry )" +
")" );
System.out.println(
"Table JJJJData was created.");
for (int i = 0; i < SQLData.length; i++)
{
iRowCount +=
stmt.executeUpdate(
"INSERT INTO socott.JJJJData VALUES " +
SQLData[i] );
}
System.out.println( iRowCount +
" Rows inserted into JJJJData.");
}
catch ( Exception e )
{
System.err.println(
"problem with SQL sent to " + sURL + ":" );
System.err.println( e.getMessage() );
}
finally
{
try { stmt.close(); }
catch( Exception e ) {}
try { con.close(); }
catch( Exception e ) {}
} // end finally clause
} // end main
} // end class Create4JData