2012-12-26 25 views
0

我是GWT的新手。我想我的Oracle10g数据库连接到GWT服务器程序,我使用这个代码 :如何将GWT连接到Oracle数据库

public class Database_connect 
{ 
    public static void connect() 
    { 
     System.out.println("This is a test project"); 
     Connection con=null; 

     try 
     { 
      Class.forName("oracle.jdbc.OracleDriver"); 
      System.out.println("Oracle JDBC driver loaded ok."); 
      con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","naren", "naren"); 
      System.out.println("Connected with @localhost:1521:XE."); 
      System.out.println("We have done it successfully"); 
     } 
     catch(Exception e) 
     { 
      System.out.println(e); 
     } 

    } 
}  

在服务器上的文件我打电话connect()功能

public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService 
{ 
    public String greetServer(String input) throws IllegalArgumentException 
    { 
     Database_connect.connect(); 
    } 
} 

但它的示值误差。

我不知道现在该做什么。任何人都帮助我。感谢您的提前。

误差

[WARN] failed [email protected] 
    java.net.BindException: Address already in use: bind 
    at sun.nio.ch.Net.bind0(Native Method) 
    at sun.nio.ch.Net.bind(Unknown Source) 
    at sun.nio.ch.Net.bind(Unknown Source) 
    at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) 
    at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) 
     at org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:205) 
    at org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:304) 
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39) 
    at org.mortbay.jetty.Server.doStart(Server.java:233) 
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39) 
    at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672) 
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509) 
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1093) 
    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:836) 
    at com.google.gwt.dev.DevMode.main(DevMode.java:311) 
[ERROR] shell failed in doStartupServer method 
+2

我建议展示错过了这个问题。我不清楚你想做什么,但我肯定这不是要走的路。您不应该以这种方式将连接代码硬连接到Java源代码中。让应用程序服务器处理这些连接参数并抽象数据源更为典型。 – duffymo

+0

未检查的异常永远不会写入'throws'。 –

+0

,但该行正在工作,当我做别的事情而不是Database_connect.connect();函数调用 – NareN

回答

0

您正在运行的项目2次,我想..please杀死在任务管理器中的所有Java进程并运行该项目只有一次..

+0

它工作thanx! – NareN

+0

这将有助于解释导致该结论的原因,例如,解释已在使用的端口意味着服务器已启动。 –