我的程序如下: import java.sql.*;public class WITableData { private final String oracleDriverName = "oracle.jdbc.driver.OracleDriver"; private final String oracleUrlToConnect ="jdbc:oracle:thin:@1.1.1.1:1521:AS7"; private Connection myConnection = null;
public WITableData() { try { Class.forName(oracleDriverName); } catch(ClassNotFoundException ex) { System.out.println(getErrorMessage(ex,"The Driver loaded error,please contact to your Software Designer!").toString()); } }
public StringBuffer getErrorMessage(Exception ex,String alarmMessage) { StringBuffer errorStringBuffer = new StringBuffer(); errorStringBuffer.append(alarmMessage); errorStringBuffer.append(ex.getMessage()); return errorStringBuffer; }
/** * getConnection method * @return Connection */ public Connection getConnection() { try { this.myConnection = DriverManager.getConnection(oracleUrlToConnect,"1","1"); System.out.print("connection successfully"); } catch(Exception ex) { System.out.println(getErrorMessage(ex,"Can not get connection,please contact to your Software Designer!").toString()); }
return this.myConnection;
}
/** * @param args */ public static void main(String[] args) { WITableData wi = new WITableData(); try { Connection myConnection = wi.getConnection(); System.out.println("Now begin to excute............."); } catch(Exception ex) { System.out.println(wi.getErrorMessage(ex,"Application error,please contact to your Software Designer!").toString()); } } }运行以后,总是报异常,所以我想问问是不是我的客户端环境配置的问题?
异常:The Driver loaded error,please contact to your Software Designeroracle.jdbc.driver.OracleDriver Can not get connection,please contact to your Software Designer!No suitable driverNow begin to excute.............
import java.sql.*;public class WITableData {
private final String oracleDriverName = "oracle.jdbc.driver.OracleDriver";
private final String oracleUrlToConnect ="jdbc:oracle:thin:@1.1.1.1:1521:AS7";
private Connection myConnection = null;
public WITableData()
{
try
{
Class.forName(oracleDriverName);
}
catch(ClassNotFoundException ex)
{
System.out.println(getErrorMessage(ex,"The Driver loaded error,please contact to your Software Designer!").toString());
}
}
public StringBuffer getErrorMessage(Exception ex,String alarmMessage)
{
StringBuffer errorStringBuffer = new StringBuffer();
errorStringBuffer.append(alarmMessage);
errorStringBuffer.append(ex.getMessage());
return errorStringBuffer;
}
/**
* getConnection method
* @return Connection
*/
public Connection getConnection()
{
try
{
this.myConnection = DriverManager.getConnection(oracleUrlToConnect,"1","1");
System.out.print("connection successfully");
}
catch(Exception ex)
{
System.out.println(getErrorMessage(ex,"Can not get connection,please contact to your Software Designer!").toString());
}
return this.myConnection;
}
/**
* @param args
*/
public static void main(String[] args) {
WITableData wi = new WITableData();
try
{
Connection myConnection = wi.getConnection();
System.out.println("Now begin to excute.............");
}
catch(Exception ex)
{
System.out.println(wi.getErrorMessage(ex,"Application error,please contact to your Software Designer!").toString());
}
}
}运行以后,总是报异常,所以我想问问是不是我的客户端环境配置的问题?
说明你还没有吃透JDBC的基本原理。
Class.forName(oracleDriverName)会在JVM加载对应Driver的字节码。抛出的异常说明是找不到对应的字节码文件。
现在知道要干什么了吧?
你不要说不会配claspath吧...
另外jdk 1.6都出来了能不能别用 classes12.jar了。