laoding
          本來我以為,隱身了別人就找不到我,沒有用的,像我這樣拉風(fēng)的男人,無論走到哪里,都像在黑暗中的螢火蟲一樣,那樣的鮮明,那樣的出眾。我那憂郁的眼神,稀疏的胡茬,那微微隆起的將軍肚和親切的笑容......都深深吸引了眾人......
          posts - 0,  comments - 37,  trackbacks - 0
          首先要把mysql的數(shù)據(jù)庫連接驅(qū)動加入到工程當(dāng)中
          代碼只要修改下sql語句、數(shù)據(jù)庫、表以及用戶名和密碼


          import java.sql.Connection;
          import java.sql.DriverManager;
          import java.sql.ResultSet;
          import java.sql.SQLException;
          import java.sql.Statement;

          /*
           * Create Date:2008-9-4 下午02:27:36
           *
           * Author:dingkm
           *
           * Version: V1.0
           *
           * Description:對進(jìn)行修改的功能進(jìn)行描述
           *
           *
           */

          public class DBConnection {

          //測試主方法
           public static void main(String[] args) {


            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();
            String sql = "select * from newitem";
            ResultSet rs = db.getResultSet(sql, conn);
            try {
             while (rs.next()) {
              String title = rs.getString("title");
              System.out.println(title);
              }
            } catch (SQLException e) {
            
             e.printStackTrace();
            }
           
           }

          //得到Connection 
           public Connection getConnection() {
            Connection conn = null;
            try {
             Class.forName("com.mysql.jdbc.Driver").newInstance();

             // 建立到MySQL的連接
             conn = DriverManager.getConnection(
               "jdbc:mysql://localhost:3306/ding", "root", "ding");
            } catch (Exception e) {
             System.out.println("數(shù)據(jù)庫連接異常!");
             e.printStackTrace();
            }
            return conn;
           }

          //得到ResultSet 
           
          public ResultSet getResultSet(String sql, Connection conn) {
            ResultSet rs = null;
            Statement stmt = null;
            try {
             stmt = conn.createStatement();
             rs = stmt.executeQuery(sql);
            } catch (Exception e) {
             e.printStackTrace();
            }
            return rs;
           }
          }


          執(zhí)行就可以連接數(shù)據(jù)庫了
          posted on 2008-09-04 19:06 老丁 閱讀(226) 評論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          本博客主為學(xué)習(xí)和復(fù)習(xí)之用,無關(guān)其他,想罵人的繞道
          Email:dkm123456@126.com
          大家一起交流進(jìn)步
          QQ:283582761


          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          留言簿(4)

          我參與的團(tuán)隊

          文章分類(50)

          文章檔案(48)

          相冊

          朋友

          搜索

          •  

          積分與排名

          • 積分 - 96598
          • 排名 - 600

          最新評論

          主站蜘蛛池模板: 民县| 长治市| 聂荣县| 高雄市| 贺州市| 黄浦区| 桓仁| 珲春市| 莆田市| 天台县| 辉县市| 哈巴河县| 河间市| 姜堰市| 铁力市| 平邑县| 离岛区| 郯城县| 阳朔县| 藁城市| 开江县| 广西| 林西县| 宁国市| 额尔古纳市| 高青县| 贵阳市| 贵州省| 剑川县| 富川| 阜新| 岗巴县| 施甸县| 棋牌| 阳城县| 环江| 呈贡县| 乐陵市| 呼和浩特市| 福贡县| 大关县|