国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

連接MySQL并執(zhí)行Select

2019-11-18 16:06:43
字體:
供稿:網(wǎng)友
/*
Database PRogramming with JDBC and java, Second Edition
By George Reese
ISBN: 1-56592-616-1

Publisher: O'Reilly
*/

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

/**
 * Example 3.1.
 */
public class Select {
  public static void main(String args[]) {
    String url = "jdbc:msql://carthage.imaginary.com/ora";
    Connection con = null;

    try {
      String driver = "com.imaginary.sql.msql.MsqlDriver";

      Class.forName(driver).newInstance();
    } catch (Exception e) {
      System.out.println("Failed to load mSQL driver.");
      return;
    }
    try {
      con = DriverManager.getConnection(url, "borg", "");
      Statement select = con.createStatement();
      ResultSet result = select
          .executeQuery("SELECT test_id, test_val FROM test");

      System.out.println("Got results:");
      while (result.next()) { // process results one row at a time
        int key = result.getInt(1);
        String val = result.getString(2);

        System.out.println("key = " + key);
        System.out.println("val = " + val);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (con != null) {
        try {
          con.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
}

(出處:http://www.survivalescaperooms.com)



發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 当雄县| 娄烦县| 金昌市| 扎赉特旗| 武清区| 平遥县| 邵东县| 都兰县| 民权县| 开江县| 德惠市| 曲阜市| 南木林县| 东光县| 米易县| 冕宁县| 德阳市| 固始县| 淮安市| 翁源县| 阿克苏市| 方正县| 天气| 青河县| 读书| 浪卡子县| 海安县| 台江县| 福泉市| 靖远县| 安泽县| 许昌市| 沙湾县| 四平市| 莒南县| 罗田县| 安新县| 衡南县| 县级市| 安远县| 通海县|