我想在java web應用程序中連接到數據庫。我在servlet中編寫了這段代碼,並添加了相關的jar文件(ojdbc),但是當我運行它時,它給了我這個錯誤: 拋出java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver錯誤-java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver
public class DBConnection extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public DBConnection() {
super();
// TODO Auto-generated constructor stub
}
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Connection con = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.101.84:1521:orcl","XXXX","XXXX");
if(con!=null)
System. out.println("Connection Successful");
else
System. out.println("error");
}
catch (Exception e) {
//System.out.println(e);
}
...
我應該怎麼辦?
你把JAR放在哪裏?在'WEB-INF/lib'下放置'classes12.jar'。 – NINCOMPOOP
你在班級路徑中有那個jar嗎?你把那個罐子放在哪裏?您正在使用哪個應用程序服務器 – Veera
閱讀[本](http://stackoverflow.com/questions/8007174/what-jdbc-jar-to-use-with-oracle-11g-jdk-1-6-and-how-to-connect-to- the-db-itse)更多。 – NINCOMPOOP