GWT - Oracle JDBC 连接问题
我在连接到 Oracle 数据库 OJDBC 时遇到很大困难。
Error:
“无法连接到数据库。异常消息:I/O 错误:网络适配器无法建立连接”
我正在使用 Google Web Toolkit,并且已将 SQL 数据库添加到我的项目中。
数据库名称是议程。
我查了很多资料,看来这个问题是很多人的共同问题,但无法解决这个问题。 我已经下载了“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 连接描述符
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来您的连接被 Oracle 数据库拒绝。您确定您的 Oracle 数据库已启动并正在运行吗?很久以前我也遇到过类似的问题,我认为没有必要安装 MYSQL 数据库来运行示例。我错了,必须安装才能运行。
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 中获得了很多乐趣。
尝试 tnsping 验证您的数据库是否已启动并运行连接器。
This Error occurs under lots cicumstances:
I had lots of fun with Oracle.
Try tnsping to verify your database has a connector up and running.
通常,当我的数据库 URL 对于相关驱动程序而言格式错误,或者我的用户名和密码不正确或传递错误时,我会看到这种情况。
我所做的是使用 IDE 的数据库插件连接到数据库,并使用与我的代码相同的驱动程序,并在尝试通过代码进行连接之前使其正常工作。
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.
这是 Google App Engine 的问题。在外部服务器上运行您的应用程序。
这是有用的链接
如何为 Tomcat 设置 GWT?
it is a Google App Engine problem. Run your application on an external server.
here is useful link
How to setup GWT for Tomcat?