2012-12-26 26 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

這將有助於解釋導致該結論的原因,例如,解釋已在使用的端口意味着服務器已啓動。 –