GWT - Oracle JDBC连接问题

时间:2011-01-31 20:59:30

标签: java oracle gwt jdbc

我很难连接到Oracle数据库OJDBC。

Error:    

“无法连接到数据库。异常消息:I / O错误:网络适配器无法建立连接”

我正在使用Google Web Toolkit,并在我的项目中添加了一个SQL数据库 数据库名称是Agenda。

我搜索了很多,看来这个问题对很多人来说很常见,但无法克服这个问题。 我已经下载了“ojdbc6.jar”并添加到我的BUILDPATH中 我已经刷新,关闭,打开并重新打开,但我仍然看到错误。

我的规格:
Windows 7 x64
Springsource - 也在Eclipse中尝试过

private static final long serialVersionUID = 1L;
private Connection connection = null;
private Properties props = null;
private ClassLoader cl = null;
private String databaseURL = "";
private String databaseUser = "";
private String databasePass = "";
public void init() {
    try {
        // Load the database connection properties from com.gwt.agenda.GWTAgendaSample.properties
        props = new Properties();
        cl = this.getClass().getClassLoader();
        InputStream is = cl.getResourceAsStream("com/gwt/agenda/GWTAgendaSample.properties");
        props.load(is);
        // Load the database access information
        databaseURL = props.getProperty("databaseURL");
        databaseUser = props.getProperty("databaseUser");
        databasePass = props.getProperty("databasePass");
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("Error loading GWTAgendaSample.properties file.", e);
    }
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        // Connect to the database
        connection = DriverManager.getConnection(databaseURL, databaseUser, databasePass);
    } catch (SQLException se) { messageOut = "Unable to connect to database. Exception message: " + se.getMessage();
        System.out.println(messageOut);
        se.printStackTrace();
        // Server side log
        logger.error(messageOut + "\n", se);
        destroy();
    } catch (Exception e) {
        messageOut = "Unable to connect to database. Exception message: " + e.getMessage();
        System.out.println(messageOut);
        e.printStackTrace();
        // Server side
        logger.error(messageOut + "\n", e);
        destroy();
    }
}

有人能指出我正确的方向。 我错过了什么吗?

请帮忙!

编辑!!

Unable to connect to database. Exception message: Erro de E/S: The Network Adapter could not establish the connection
java.sql.SQLRecoverableException: Erro de E/S: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.gwt.Agenda.server.GreetingServiceImpl.init(GreetingServiceImpl.java:78)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
    at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:342)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:463)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:375)
    at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422)
    at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:678)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:238)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1054)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:308)
    ... 27 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:209)
    at oracle.net.nt.ConnOption.connect(ConnOption.java:123)
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:353)
    ... 32 more
  

无法连接到数据库。   异常消息:监听器被拒绝   与以下连接   错误:ORA-12505,TNS:听众   目前还不知道给出的SID   连接描述符

4 个答案:

答案 0 :(得分:2)

此错误发生在许多情况下:

  1. 未配置TNS-Listener
  2. TNS-Listerner表现出色但没有跑步
  3. 连接网址中的TNS名称错误
  4. 系统路径中的多个TNSNAMES.ORA
  5. 我对Oracle有很多乐趣。 尝试tnsping验证数据库是否已启动并运行连接器。

答案 1 :(得分:2)

听起来您的连接被Oracle数据库拒绝了。您确定您的Oracle数据库已启动并正在运行吗?很久以前我遇到过类似的问题,认为没有必要安装MYSQL数据库来运行一个例子。我错了,不得不安装让它运行。

答案 2 :(得分:1)

通常我会在我的数据库网址格式错误的情况下看到相关驱动程序或我的用户名和密码不正确或传输错误。

我所做的是使用IDE的插件连接到数据库,并使用与我的代码相同的驱动程序,并在尝试连接代码之前使其运行。

答案 3 :(得分:0)

这是Google App Engine的问题。在外部服务器上运行您的应用程序。

这里是有用的链接 How to setup GWT for Tomcat?