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

时间:2016-01-27 03:49:14

标签: java oracle jdbc oracle11g

我从最近3天将我的jdbc程序连接到oracle时出错了我试图使用我从谷歌获得的在线解决方案来解决这个问题但它无法解决我的问题这是我的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());
   }
  }
}
使用命令提示符编译from时得到的错误,我的listener.ora文件看起来像这样

我的oracle版本是版本11.2.0.2.0

我的jdbc驱动程序版本是 ojdbc6-11.2.0.2.0 this is the status of mylistener which i got with<code>>lsnrctl stat</code>

error while compile the java program

my listener.ora file look like this

当我使用命令提示符编译程序时,这是我的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

我试图通过以下链接解决此错误,我在谷歌搜索时发现

solution which is from the stackoverflow

coderech solution

another solution which i got from the stackoverflow

但最后我所有的工作我都无法解决这个问题,如果有人知道解决方案,那么请给出解决方案,请对我有用并提前感谢.....希望得到答案

1 个答案:

答案 0 :(得分:0)

你的实例/ SID错误(ex)。它应该是:

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