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

» JWorld@TW » JDBC/SQL討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 快速測試 JSP + Mysql [by iampoya] [精華]
browser

戀香

版主

發文: 3570
積分: 1
於 2003-06-19 18:36 user profilesend a private message to usersend email to browserreply 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://www.mysql.com/downloads/api-jdbc-stable.html
Download Connector/J 3.0
檔名應該是叫mysql-connector-java-3.0.8-stable-bin.jar
測試程式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.sql.*;
class TestJDBCMySQL
{
  public static void main(String[] args) throws Exception
  {  
    Class.forName("com.mysql.jdbc.Driver").newInstance(); 
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?user=root");
    String sql = "select * from user ";
    Statement stmt = con.createStatement();
    stmt.execute(sql);
    ResultSet rs = stmt.getResultSet();
    for(int i = 1;i <= rs.getMetaData().getColumnCount();i++) {
      System.out.print(rs.getMetaData().getColumnName(i) + "\t") ;
    }
    System.out.println( System.getProperty("line.separator")+"********************");
    while (rs.next()) {
      for(int i = 1;i <= rs.getMetaData().getColumnCount();i++) {
        System.out.print(rs.getString(i) + "\t");
      }
      System.out.println();
    }
  }
}

Good Luck !!


morchory edited on 2005-08-21 02:49
reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
iampoya

Speculator

版主

發文: 169
積分: 8
於 2003-06-19 18: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
果然是neo
速度真快

才剛po
怎麼轉過來就被收文了 :p


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
JiaYun



版主

發文: 761
積分: 9
於 2003-06-19 18:44 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
呵呵, 把標記關掉 code 裡面才不會有燈泡呦

reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:iampoya]
browser

戀香

版主

發文: 3570
積分: 1
於 2003-06-19 18:49 user profilesend a private message to usersend email to browserreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
iampoya wrote:
果然是neo
速度真快

才剛po
怎麼轉過來就被收文了 :p


這樣子以後有問題的人 ...
可以用search去找 ..
也不用一問在問 ... 浪費大家的時間 ...

大家不覺得bbs就是如此嗎 .....


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
zhshfeng_xx





發文: 301
積分: 3
於 2004-01-15 14:49 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:快速測試 JSP + Mysql [by iampoya] [Re:zhshfeng_xx]
TAHO

可愛吧∼∼

版主

發文: 271
積分: 7
於 2004-01-15 15:17 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
不過是 typo,而且又「不是」與利益相關的正式文件,又不會造成看的人誤會其意思,不需要太在意吧∼∼

會把『再』打成『在』的原因是因為輸入法軟體的關係
使用像「微軟新注音」,或是「自然輸入法」,這種會自動選字的軟體
程式很容易選到錯誤的同音字,只要打字的人一個閃神沒注意,就會出錯
這不過是小事情罷了∼∼∼


reply to postreply to post
請養成良好的 Java 程式碼慣例 習慣
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
BenClick





發文: 3
積分: 0
於 2004-02-07 00: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
不過我試過, 我connect唔到
我已經照Download Connector/J 3.0 readme檔咁set
放左mysql-connector-java-3.0.10-stable-bin.jar係C:\j2sdk1.4.2_03\jre\lib\ext\內

CLASSPATH係c:\j2sdk1.4.2_03\lib\tools.jar;C:\j2sdk1.4.2_03\lib\dt.jar;C:\j2sdk1.4.2_03\jre\lib\ext\mysql-connector-java-3.0.10-stable-bin.jar;

但係都唔work, 係未我set漏野

請幫忙!!!!!!


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
fatdog





發文: 7
積分: 0
於 2004-08-31 10: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
你應該將mysql-connector-java-3.0.10-stable-bin.jar
放係 c:\tomcat\common\lib


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
jonz

我是粽子



發文: 18
積分: 0
於 2004-09-09 13:11 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
正好要用,
拿來試試看~~
謝謝~~Big Smile


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
itsayr





發文: 14
積分: 0
於 2004-11-21 19:06 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
不好意思!
我照著試了又試,但都不行,
所以想請問一下,是我把最上面給的那個程式碼的server、id、passwd、.... 改好後執行,就可以測試了嗎?還是有其它方法嗎??

我已經把mysql-connector-java-3.0.16-ga-bin.jar copy 到tomcat/common/lib 下了,但卻不知道要怎麼辦,那位高手可以幫幫我的呢??

thx..


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
hkdennis2k





發文: 1926
積分: 6
於 2004-12-07 11:27 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
我倒想問問為甚麼這是 [精華]......

"快速測試 JSP + Mysql"
有誰看到 JSP 或和 Servlet 甚至 applet 相關的???????

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package tw.com.javaworld.test;
import java.sql.*;
class TestJDBCMySQL{
  public static void main(String[] args) throws Exception {  
    if(args.length<2){
       throw new IllegalArgumentException(args);
    }
    try{
       Class.forName(args[0]); 
    }catch(Exception e){
       System.err.println(args[0]+" not found, make sure it is on your classpath");
    }
    Connection con =null;
 
    try{
        try{
            con=DriverManager.getConnection(args[1]);
        }catch(Exception e){
           System.err.println(args[1]+" is invalid");
           System.exit(-1);
        }
        StringBuffer sql=new StringBuffer();
        for(int i=2;i<args.length;i++)
            sql.append(args[i]).append(' ');
        Statement stmt = con.createStatement();
        stmt.execute(sql);
        ResultSet rs = stmt.getResultSet();
        for(int i = 1;i <= rs.getMetaData().getColumnCount();i++) {
          System.out.print(rs.getMetaData().getColumnName(i));
          System.out.print('\t');
        }
        System.out.println();
        System.out.println("********************");
        while (rs.next()) {
          for(int i = 1;i <= rs.getMetaData().getColumnCount();i++) {
            System.out.print(rs.getString(i));
            System.out.print('\t');
          }
          System.out.println();
          for(int i = 1;i <= rs.getMetaData().getColumnCount();i++) {
            System.out.print(rs.getObject(i).getClass().getName());
            System.out.print('\t');
          }
          System.out.println();
        }
    }finally{
       con.close();
    }
  }
}


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:hkdennis2k]
worookie

Small Ship

版主

發文: 2092
積分: 21
於 2004-12-07 13:41 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
hkdennis2k wrote:
我倒想問問為甚麼這是 [精華]......


這些精華文章都是有歷史價值意義的
一年半前會取該標題會被標為精華一定都有其原因的
(一年半前本網站叫做 JSPtw, 那時還不叫作 JavaWorld@TW)
若我是在一年半前看到這篇文章, 我也是一定馬上把他列為精華的

比如說現在大家坐飛機隨時都可以到美洲, 去看看美洲是件很容易的事.
可是現在並沒有人質疑當時哥倫布發現新大陸時是件不值得注意的事.


worookie edited on 2004-12-07 13:46
reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
emt2a7





發文: 71
積分: 3
於 2005-05-26 10:22 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
對不起,我請問一下:
我會出現一個 Exception :
java.lang.NoClassDefFoundError: org/aspectj/lang/Signature

我有順便把 jdbc for Mysql 的其他 *.jar 給設定好,
可是還是會出現同樣的 Exception 訊息。

請問是什麼樣的狀況??有可以解決的方法嗎? ~~ 新手


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
emt2a7





發文: 71
積分: 3
於 2005-05-26 11:17 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 連接 MySQL。

因為我原本使用 mysql-connector-java-3.1.8a

後來我改用 mysql-connector-java-3.0.16-ga 就可以了。

至於原因我就不甚清楚了。


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:emt2a7]
YAMAHA50164





發文: 9
積分: 0
於 2005-06-01 15:13 user profilesend a private message to usersend email to YAMAHA50164reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
emt2a7 wrote:
不好意思,我解決了,我可以用 Java 連接 MySQL。

因為我原本使用 mysql-connector-java-3.1.8a

後來我改用 mysql-connector-java-3.0.16-ga 就可以了。

至於原因我就不甚清楚了。


請問一下你有設定什麼路徑嗎?
我也是有發生跟你一樣的問題

我是用eclipse + jdk1.5 + tomcat5.5 + MySQL
假設我都只有剛把設些程式裝好什麼都還沒設定的話
有哪些要設定的?


reply to postreply to post
作者 Re:快速測試 JSP + Mysql [by iampoya] [Re:browser]
StephenHuang





發文: 15
積分: 0
於 2006-05-02 13:47 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
請問一下!
我是用resin server也可以這樣子設定嗎?


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