问题描述:
1.环境:myeclipse jdk1.5(开始是1.6),tomcat5.5 数据库oracle10g
2.jar包用了ojdbc14(jdk11.4)ojdk5 ojdk6
进行简单的jdbc连接,代码如下:
private static String driver = "oracle.jdbc.driver.OracleDriver";
private static String url = "jdbc.oracle.thin@127.0.0.1:1521:power";
private static String user = "power";
private static String pass = "power";
private static Connection connection = null;
public static Connection getConnection() throws SQLException{
if(null == connection){
initConnection();
}
else if(connection.isClosed()){
connection.close();
initConnection();
}
return connection;
}
public static void initConnection(){
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, user,pass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
3.错误
主要是说 no suitable driver
以前碰到过类似的问题,就是连接数据库的JDBC版本不对(以前针对MYSQL,找了N多个版本)
今天找了ORACLE 10G的版本,可一个都不行,请问该这是什么问题
以前是具体错误:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.zhangxy.dbconnection.StaticConnection.initConnection(StaticConnection.java:30)
at com.zhangxy.dbconnection.StaticConnection.getConnection(StaticConnection.java:16)
at com.zhangxy.dbo.VoteManager.addVote(VoteManager.java:14)
at com.zhangxy.Servlet.addMessage.doPost(addMessage.java:72)
at com.zhangxy.Servlet.addMessage.doGet(addMessage.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
at java.lang.Thread.run(Thread.java:595)
------解决方案--------------------
是没class12.jar嘛??