Here is an example of connectivity ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // First load the driver classes String driverName = "weblogic.jdbc.mssqlserver4.Driver"; try
{
Class.forName(driverName).newInstance();
System.out.println("\n loadDrivers: "+
"SQL Server 7 Type 4 driver classes: "+
" successfuly loaded \n");
}
catch(java.lang.IllegalAccessException e)
{
System.err.print("loadDrivers: "+
"Illegal acess exception caught: ");
System.err.println(e.getMessage());
} catch(java.lang.InstantiationException e)
{
System.err.print("loadDrivers: "+
"Illegal acess exception caught: ");
System.err.println(e.getMessage()); }
catch(java.lang.ClassNotFoundException e)
{
System.err.print("loadDrivers: "+
"class not found caughtfor driver: \n" );
System.err.println(e.getMessage()); }
} // Connect to datbase
/* Assuming your SQL server 7 database name is demoSQL7
* located on the Server DEMOSERVER with access info
* User = "avijit" and Password = "dutta"
****************************************************/ Properties dbProp = new Properties();
dbProps.put("user", "avijit");
dbProps.put("password", "dutta") ; String hostName = "DEMOSERVER";
String databaseName = "demoSQL7"; String databaseURL = "jdbc:weblogic:mssqlserver4:"+
database+"@"+hostName+":1433"; Connection con = null; try
{ con = DriverManager.getConnection(DBurl, dbProps); System.out.println(" ConnectToDB: Successful " +
" connection to database: "+database); }
catch (SQLException ex)
{
System.err.println(" ConnectToDB:***** Failed "+
connection to database: "+database);
System.err.println(" ConnectToDB:setConnection: "+
" Exception message "+ex.getMessage());
con = null;
}
} ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
Class.forName(driverName).newInstance();
System.out.println("\n loadDrivers: "+
"SQL Server 7 Type 4 driver classes: "+
" successfuly loaded \n");
}
catch(java.lang.IllegalAccessException e)
{
System.err.print("loadDrivers: "+
"Illegal acess exception caught: ");
System.err.println(e.getMessage());
} catch(java.lang.InstantiationException e)
{
System.err.print("loadDrivers: "+
"Illegal acess exception caught: ");
System.err.println(e.getMessage()); }
catch(java.lang.ClassNotFoundException e)
{
System.err.print("loadDrivers: "+
"class not found caughtfor driver: \n" );
System.err.println(e.getMessage()); }
} // Connect to datbase
/* Assuming your SQL server 7 database name is demoSQL7
* located on the Server DEMOSERVER with access info
* User = "avijit" and Password = "dutta"
****************************************************/ Properties dbProp = new Properties();
dbProps.put("user", "avijit");
dbProps.put("password", "dutta") ; String hostName = "DEMOSERVER";
String databaseName = "demoSQL7"; String databaseURL = "jdbc:weblogic:mssqlserver4:"+
database+"@"+hostName+":1433"; Connection con = null; try
{ con = DriverManager.getConnection(DBurl, dbProps); System.out.println(" ConnectToDB: Successful " +
" connection to database: "+database); }
catch (SQLException ex)
{
System.err.println(" ConnectToDB:***** Failed "+
connection to database: "+database);
System.err.println(" ConnectToDB:setConnection: "+
" Exception message "+ex.getMessage());
con = null;
}
} ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
然后在工程中使用这个包
在tools/enterprise setup里的database drivers选项卡中加入这个包。
在jdbc explorer中加入这个驱动程序的驱动名
就可以使用这个驱动了。
"weblogic.jdbc.mssqlserver4.Driver" 这个驱动放在 Weblogic 的哪个地方???
只要在classpath中加入此.jar 即可,