简体   繁体   中英

problem in connecting to oracle 10g express edition through java

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:1521: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");

您可能需要在“ jdbc:oracle:thin:@localhost:1521:system”中用XE替换系统。

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

删除'e'和'r'之间的空格?

您的类路径中有Oracle驱动程序吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM