JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » JDBC/SQL討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 要取得JDBC連結後,卻出問題
hilliverson





發文: 4
積分: 0
於 2011-10-24 17:26 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最近小弟遇到個問題,就是我們拿JDBC去做資料庫連結時,發現執行到某一段程式後,卻不動了。

AP Server是windows 2008 R2
DB 是SQL Server 2008
Web Server是Tomcat

程式碼如下:
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://XXXXX:1433";
String user = "XXXX";
String password = "XXXXX";
Connection conn = null;
Statement stmt = null;
try
{
System.out.print("0");
Class.forName(driver);
System.out.print("1");
conn = DriverManager.getConnection(url, user, password);
System.out.print("2");
stmt = conn.createStatement();
System.out.print("3");
ResultSet result = stmt.executeQuery("SELECT * FROM bas");
System.out.print("4");
System.out.print(result.getString(1) + "\t");
System.out.print(result.getString(2) + "\t");
System.out.print(result.getString(3) + "\t");
System.out.print(result.getString(4) + "\t");
System.out.println(result.getString(5) + "\t");


}
catch(ClassNotFoundException e)
{
System.out.println("找不到驅動程式");
e.printStackTrace();
}
catch(SQLException e)
{
System.out.println("找不到驅動程式2");
e.printStackTrace();
}
finally
{
if(stmt != null)
{
try
{
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
if(conn != null)
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}

只要執行到conn = DriverManager.getConnection(url, user, password);
此行,就整個程式等在那邊不動。而且也沒有任何錯誤訊息。

也曾去看SQL Server的活動監控,發現我們的process是有登入到SQL Server的。
不知道這是什麼原因,不知道有沒有人遇過?


reply to postreply to post
作者 Re:要取得JDBC連結後,卻出問題 [Re:hilliverson]
roytsang





發文: 620
積分: 1
於 2011-10-24 17:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你有download 最新版的MS SQL server jdbc driver 嗎?

reply to postreply to post
作者 Re:要取得JDBC連結後,卻出問題 [Re:roytsang]
hilliverson





發文: 4
積分: 0
於 2011-10-24 18:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
下載的是sqljdbc_3.0.1301.101_cht 這各版本

reply to postreply to post
作者 Re:要取得JDBC連結後,卻出問題 [Re:hilliverson]
roytsang





發文: 620
積分: 1
於 2011-10-25 09:15 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我估計可能是security 問題?我不肯定呀

reply to postreply to post
作者 Re:要取得JDBC連結後,卻出問題 [Re:hilliverson]
winddknight





發文: 162
積分: 0
於 2011-10-25 14:21 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
String url = "jdbc:sqlserver://XXXXX:1433";


你有給資料庫名稱嗎?

http://caterpillar.onlyfun.net/Gossip/JavaGossip-V2/ConnectDB.htm


reply to postreply to post
作者 Re:要取得JDBC連結後,卻出問題 [Re:winddknight]
roytsang





發文: 620
積分: 1
於 2011-10-25 15:42 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看一看這個能幫到你嗎?
http://msdn.microsoft.com/en-us/library/ms378428.aspx


reply to postreply to post
作者 Re:要取得JDBC連結後,卻出問題 [Re:roytsang]
hilliverson





發文: 4
積分: 0
於 2011-10-29 22:50 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最後的解法是把JDBC換成jtds-1.2.5.jar,才把這問題解決。

reply to postreply to post
» JWorld@TW »  JDBC/SQL討論區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8