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

» JWorld@TW » JDBC/SQL討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 java 無法連接mysql.....
x3711699





發文: 148
積分: 4
於 2004-04-09 16:51 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
mysql版本:4.0.18
os:win98
j2sdk1.4.1_01
mysql-connector-java-3.1.0-alpha-bin

如題
我寫了一個測試小程式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.sql.*;
 
public class Sample
{ 
 public static void main(String[] args) 
 {
  try
  {
   Class.forName("org.gjt.mm.mysql.Driver");
 
   Connection MyConn = DriverManager.getConnection("jdbc:mysql://localhost/test","temp","1234");
 
   System.out.println("資料庫連線成功");
 
  }
 
  catch(ClassNotFoundException e)
  {
 
    System.out.println("找不到連線類別檔案");
  }
  catch(SQLException e)
  {
   System.out.println("資料庫無法連線!!");
   System.out.println("請檢查帳號及密碼是否有誤,");
   System.out.println("或者 MySQL 服務是否關閉。");
 
  }
 } 
}


結果:
1
2
C:\j2sdk1.4.1_01\bin>java Sample
Exception in thread "main" java.lang.NoClassDefFoundError: Sample


請問到底是那裡出了問題???


reply to postreply to post
作者 Re:java 無法連接mysql..... [Re:x3711699]
anthonychen

外線交給我

版主

發文: 2033
積分: 8
於 2004-04-09 17:01 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
請自行查看新手區的FAQ: 常見Java例外處理

reply to postreply to post
作者 Re:java 無法連接mysql..... [Re:x3711699]
x3711699





發文: 148
積分: 4
於 2004-04-09 19:56 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
十分感謝!!

問題終於獲得解決!!
(害我還用全文檢索找了半天.....)

人因挫折而成長


reply to postreply to post
作者 Re:java 無法連接mysql..... [Re:x3711699]
peterjan





發文: 1
積分: 0
於 2004-04-22 00:03 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
classpath未納入廠商提供的driver(xxx.zip)

reply to postreply to post
作者 Re:java 無法連接mysql..... [Re:x3711699]
anthonycs



版主

發文: 1195
積分: 6
於 2004-04-22 00: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
請多多磨練Java語言的除錯及基本功夫

恕我冒昧說句話 , 直接跳過這些 就學JDBC 是太急進了一點喔

請看 給Java新手的一封信


reply to postreply to post
新手請維持互動討論精神, 請看良好的 討論示範
作者 Re:java 無法連接mysql..... [Re:x3711699]
yenchechang





發文: 46
積分: 0
於 2004-09-07 23:41 user profilesend a private message to usersend email to yenchechangreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
基本上 若是mysql的jdbc driver沒設
應該是java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
之類的錯誤訊息
但是你上面的訊息, 明顯表示 你的Sample這個class應該也沒Compile
也就是沒正確執行完javac Sample 所以根本沒有找到Sample.class
所以你的錯誤訊息是
Exception in thread "main" java.lang.NoClassDefFoundError: Sample

所以, 請先把環境設好, 同時正確能夠編譯吧~


reply to postreply to post
作者 Re:java 無法連接mysql..... [Re:x3711699]
x3711699





發文: 148
積分: 4
於 2004-09-08 14:19 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
to yenchechang 大大:

我真不知該說什麼才是...

這篇文章是"今年四月份"的東西...

而這個問題我也早已釐清與解決了

不過 還是感謝你的回應... Black Eye


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