I'm unable to connect Oracle 10g database.I am getting exception java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver
The code is:
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException e) {
e.printStackTrace();
}
try {
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:152开发者_高级运维1:system","user" ,"pass");
stmt=con.createStatement();
}
.......
How can i proceed?
First, you have a space " "
in your driver class name
Change,
Class.forName("oracle.jdbc.driver.OracleDrive r");
to,
Class.forName("oracle.jdbc.driver.OracleDriver");
Also, fix this error from:
DriverManager.getConnection("jdbc:oracle: thin:@localhost:1521:system","user" ,"pass");
to
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:system","user" ,"pass");
You will probably need to replace system with XE in "jdbc:oracle: thin:@localhost:1521:system"
Remove the space between the 'e' and the 'r'?
You have the Oracle driver in your classpath?
Its a problem with the given url. Please correct the url with accurate host name,port no,user name & password.Do not use the port number(8080) that you are using with browser when you are running you application oracle 10g express edition.Simply user the default port number 1521.
Please find the example below:-
String driver="oracle.jdbc.driver.OracleDriver";
Class.forName(driver);
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","manoj","manoj");
- user name=manoj
- password=manoj
- port no=1521
- service name=XE
- Host=Localhost
精彩评论