Problème de Driver de connexion à Oracle
Bonjour à tout le monde,
Depuis hier soir, je suis face à une situation que je n'arrive pas à comprendre. En effet, j'ai code de connexion à une bd Oracle qui fonctionne sans problème quand je l'utilise dans une classe java avec méthode main et qui ne fonctionne pas quand je l'utilise dans une page JSP ou une Servlet.
Je vous présente les deux codes :
Code dans méthode main()
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class TestJdbc {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection con=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch(ClassNotFoundException e){
System.out.println("Driver imcompatible !");
e.printStackTrace();
}
try {
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "SYSTEM",
"fDan2014");
} catch (SQLException e) {
System.out.println("Connexion non établie !");
e.printStackTrace();
return;
}
if (con != null) {
System.out.println("Connexion établie!");
} else {
System.out.println("Connexion non établie!");
} |
Voici le même code dans une page JSP
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
<body>
<%
String idserv=request.getParameter("idservice");
String nomserv=request.getParameter("nomservice");
String interphone=request.getParameter("interphone");
int idServ=Integer.parseInt(idserv);
int phone=Integer.parseInt(interphone);
Connection con=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch(ClassNotFoundException e){
System.out.println("Driver imcompatible !");
e.printStackTrace();
}
try {
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "SYSTEM",
"fDan2014");
} catch (SQLException e) {
System.out.println("Connexion non établie!");
e.printStackTrace();
return;
}
if (con != null) {
System.out.println("Connexion établie!");
} else {
System.out.println("Connexion non établie!");
}
....
%> |
Avec la JSP j'obtiens le message d'erreur suivant :
Code:
1 2 3 4 5
| java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
........ |
J'utilise Eclipse et le driver ojdbc6.jar pour Oracle 11g.
Aidez -moi s'il vous plait.
Merci d'avance.