开发者

GWT - Oracle JDBC Connection problems

I am having great difficulty making a connection to an Oracle Database OJDBC.

Error:    

"开发者_如何学运维Unable to connect to database. Exception message: I / O Error: The Network Adapter not could Establish the connection"

I´m using Google Web Toolkit and i added a SQL Database to my project.

The Database name is Agenda.

I've searched a lot, it seems this problem is common to many people, but could not overcome this problem. I've downloaded "ojdbc6.jar" and added to my BUILDPATH.

I've refreshed, close, open and reopen, but I still see errors.

My Specs:

Windows 7 x64

Springsource - tried also in 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();
    }
}

Can someone point me in the right direction. Am i missing something?

Please help!

Edited!!

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

Unable to connect to database. Exception message: Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor


It sounds like your connection is refused by Oracle database. Are you sure your Oracle database is up and running? I had a similar problem a long time ago and thought wasn´t necessary to install a MYSQL database to run a example. I was wrong and had to install to make it running.


This Error occurs under lots cicumstances:

  1. No TNS-Listener configured
  2. TNS-Listerner confugured but not running
  3. Wrong TNS Name in the connection URL
  4. More than one TNSNAMES.ORA in the system path

I had lots of fun with Oracle. Try tnsping to verify your database has a connector up and running.


Usually I see this when my DB URL is badly formatted for the driver in question or my username and password are incorrect or being passed incorrectly.

What I do is connect to the db using a db plugin for the IDE and the same driver as my code will use and get that to work before trying to connect through the code.


it is a Google App Engine problem. Run your application on an external server.

here is useful link How to setup GWT for Tomcat?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜