- 论坛徽章:
- 0
|
写了一个方法:
private Connection getConnection(){
Connection con = null;
String driverName = "oracle.jdbc.driver.OracleDriver";
//url
String url = "jdbc racle:thin 127.0.0.1:1521:myoracle";
String user = "system";
String password = "myoracle";
try{
if(con == null)
con = DriverManager.getConnection(url,user,password);
}catch(Exception e){
e.printStackTrace();
}
return con;
}
在JSP文件里面调用这个类的这个方法,可以连接数据库,但是在这个类的main()方法里面调用此方法,就报错:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
真是搞不懂了。 |
|