简体   繁体   English

将jdbc连接到Oracle数据库时出错

[英]Error while connecting jdbc to the oracle database

i get the error while connecting my jdbc program to the oracle from last 3 days i tries to solve this problem using the online solution which i got from the google but it cant solve my problem this is my code for sqlplus connection 我从最近3天将我的jdbc程序连接到oracle时收到错误,我尝试使用从google获得的在线解决方案来解决此问题,但这无法解决我的问题,这是我的sqlplus连接代码

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main{
   public static void main(String args[]){
      try{
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ex","system","12345");
        System.out.println(con.toString());
    }catch(Exception e){
        if(e instanceof SQLException){
            e.printStackTrace();
        }
           System.out.println(e.toString());
   }
  }
}

error that i got while compile the from with the command prompt and my listener.ora file is look like this 我在使用命令提示符编译from时遇到的错误和我的listener.ora文件看起来像这样

my oracle version is Version 11.2.0.2.0 我的oracle版本是11.2.0.2.0版

my jdbc driver version is ojdbc6-11.2.0.2.0 我的jdbc驱动程序版本是ojdbc6-11.2.0.2.0 这是我通过<code >> lsnrctl stat </ code>获得的mylistener的状态

编译Java程序时出错

我的listener.ora文件看起来像这样

this is my listener.log file while i compile the program with the command prompt 这是我的listener.log文件,同时我使用命令提示符编译程序

Wed Jan 27 08:40:20 2016
27-JAN-2016 08:40:20 * (CONNECT_DATA=(SID=ex)(CID=(PROGRAM=JDBC Thin Client)(HOST=__jdbc__)(USER=Jagdish))) * (ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=52366)) * establish * ex * 12505
TNS-12505: TNS:listener does not currently know of SID given in connect descriptor
Wed Jan 27 08:40:32 2016
27-JAN-2016 08:40:32 * service_update * xe * 0
Wed Jan 27 08:41:34 2016
27-JAN-2016 08:41:34 * service_update * CLRExtProc * 0
27-JAN-2016 08:41:36 * service_update * xe * 0
Wed Jan 27 08:43:23 2016
27-JAN-2016 08:43:23 * service_update * CLRExtProc * 0
Wed Jan 27 08:45:11 2016
27-JAN-2016 08:45:11 * service_update * CLRExtProc * 0
Wed Jan 27 08:46:57 2016
27-JAN-2016 08:46:57 * service_update * CLRExtProc * 0
Wed Jan 27 08:48:44 2016
27-JAN-2016 08:48:44 * service_update * CLRExtProc * 0
Wed Jan 27 08:50:30 2016
27-JAN-2016 08:50:30 * service_update * xe * 0
27-JAN-2016 08:50:31 * service_update * CLRExtProc * 0
Wed Jan 27 08:51:30 2016
27-JAN-2016 08:51:30 * service_update * xe * 0
27-JAN-2016 08:51:36 * service_update * xe * 0
Wed Jan 27 08:52:18 2016
27-JAN-2016 08:52:18 * service_update * CLRExtProc * 0
Wed Jan 27 08:54:05 2016
27-JAN-2016 08:54:05 * service_update * CLRExtProc * 0
Wed Jan 27 08:55:01 2016
27-JAN-2016 08:55:01 * service_update * xe * 0
Wed Jan 27 08:55:31 2016
27-JAN-2016 08:55:31 * service_update * xe * 0
Wed Jan 27 08:55:52 2016
27-JAN-2016 08:55:52 * service_update * CLRExtProc * 0
Wed Jan 27 08:57:41 2016
27-JAN-2016 08:57:41 * service_update * CLRExtProc * 0
Wed Jan 27 08:59:28 2016
27-JAN-2016 08:59:28 * service_update * CLRExtProc * 0
Wed Jan 27 09:01:16 2016
27-JAN-2016 09:01:16 * service_update * CLRExtProc * 0
Wed Jan 27 09:01:37 2016
27-JAN-2016 09:01:37 * service_update * xe * 0
Wed Jan 27 09:03:03 2016
27-JAN-2016 09:03:03 * service_update * CLRExtProc * 0
Wed Jan 27 09:03:27 2016
27-JAN-2016 09:03:27 * (CONNECT_DATA=(SID=ex)(CID=(PROGRAM=JDBC Thin Client)(HOST=__jdbc__)(USER=Jagdish))) * (ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=52658)) * establish * ex * 12505
TNS-12505: TNS:listener does not currently know of SID given in connect descriptor

and i tried to solve this error usin the following link which i found while googler 我试图通过以下链接来解决此错误,该链接是我在googler中找到的

solution which is from the stackoverflow 来自stackoverflow的解决方案

coderech solution Coderech解决方案

another solution which i got from the stackoverflow 我从stackoverflow获得的另一个解决方案

but finally all and all my work i cant able to resolve this problem please if anyone know the soltion the please give the solution it's to usefull for me please and thanks in advance.....hope to get answer 但是最后我所有的所有工作我都无法解决这个问题,如果有人知道解决方法,请给出对我有用的解决方案,并在此先感谢.....希望获得答复

You have your instance/SID the wrong way around (ex). 您的实例/ SID的处理方式错误(例如)。 It should read: 它应显示为:

Connection con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","system","12345");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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