Message-ID: <4LIUhh$CTT@bbs.cqupt.edu.cn>
Subject: 请高手指教这程序错在哪?thanks!
Date: Wed, 23 Nov 2005 14:01:31 +0000
From: Korn@bbs.cqupt.edu.cn-SPAM.no (马大哈)
Path: news.cnusenet.org!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-cn.bbs.comp.lang.java.20140731.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!news4.google.com!news.glorb.com!nntp-server.pubsub.com!news.neu.edu.cn!news.uestc.edu.cn!CQUPT
Newsgroups: cn.bbs.comp.lang.java
Organization: 幽幽黄桷兰
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: Java/M.1132754491.90
Lines: 38
Xref: news.cnusenet.org cn.bbs.comp.lang.java:19554

import java.sql.*;
public class DBConnection {
    public static Connection getConnection(){
        Connection con;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/mysql","
root","ChinaWzzxp");
            return con;
            }
        catch(ClassNotFoundException e){
            System.out.println(e.getMessage());
        }
        catch(SQLException ex){
            System.out.println(ex.getMessage());
        }
        return null;
    }

}
class OperateDB{
    public static void main(String[] args){
        Statement sta;
        Connection conn;
        try{
            conn = DBConnection.getConnection();
            sta = conn.createStatement();
            ResultSet rs = sta.executeQuery("select * from wzzchina");
        }
        catch(SQLException e){
            System.out.println(e.getMessage());
        }
    }
}

--

※ 来源:·幽幽黄桷兰 http://bbs.cqupt.edu.cn·[FROM: 172.18.102.199]