GWT - Oracle JDBC 连接问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4856028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GWT - Oracle JDBC Connection problems
提问by Martinho
I am having great difficulty making a connection to an Oracle Database OJDBC.
我在连接到 Oracle 数据库 OJDBC 时遇到了很大的困难。
Error:
"Unable to connect to database. Exception message: I / O Error: The Network Adapter not could Establish the connection"
“无法连接到数据库。异常消息:I/O 错误:网络适配器无法建立连接”
I′m using Google Web Toolkit and i added a SQL Database to my project.
The Database name is Agenda.
我正在使用 Google Web Toolkit,并在我的项目中添加了一个 SQL 数据库。
数据库名称是议程。
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.
我搜索了很多,似乎这个问题对很多人来说都很常见,但无法克服这个问题。我已经下载了“ojdbc6.jar”并添加到我的 BUILDPATH 中。
我已经刷新、关闭、打开和重新打开,但我仍然看到错误。
My Specs:
Windows 7 x64
Springsource - tried also in Eclipse
我的规格:
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();
}
}
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
无法连接到数据库。异常消息:侦听器拒绝连接并出现以下错误:ORA-12505,TNS:侦听器当前不知道连接描述符中给出的 SID
采纳答案by Ana Ferreira
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.
听起来您的连接被 Oracle 数据库拒绝了。您确定您的 Oracle 数据库已启动并正在运行吗?很久以前我也遇到过类似的问题,认为没有必要安装 MYSQL 数据库来运行示例。我错了,必须安装才能运行。
回答by Christian Kuetbach
This Error occurs under lots cicumstances:
在很多情况下会发生此错误:
- No TNS-Listener configured
- TNS-Listerner confugured but not running
- Wrong TNS Name in the connection URL
- More than one TNSNAMES.ORA in the system path
- 未配置 TNS 侦听器
- TNS-Listerner 已配置但未运行
- 连接 URL 中的 TNS 名称错误
- 系统路径中有多个 TNSNAMES.ORA
I had lots of fun with Oracle. Try tnspingto verify your database has a connector up and running.
我在 Oracle 上玩得很开心。尝试tnsping以验证您的数据库是否已启动并运行连接器。
回答by Speck
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.
通常,当我的数据库 URL 为相关驱动程序格式错误或我的用户名和密码不正确或传递不正确时,我会看到这一点。
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.
我所做的是使用 IDE 的 db 插件和与我的代码将使用的驱动程序相同的驱动程序连接到 db,并在尝试通过代码连接之前使其工作。
回答by user2517582
it is a Google App Engine problem. Run your application on an external server.
这是一个 Google App Engine 问题。在外部服务器上运行您的应用程序。
here is useful link How to setup GWT for Tomcat?
这是有用的链接 如何为 Tomcat 设置 GWT?