經(jīng)常忘的jdbc數(shù)據(jù)庫連接

          package test;

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

          public class Oracletest {

          ?/**
          ? * @param args
          ? * @throws SQLException
          ? * @throws ClassNotFoundException
          ? * @throws UnsupportedEncodingException
          ? */
          ?public static void main(String[] args) throws SQLException, ClassNotFoundException, UnsupportedEncodingException {
          ??// TODO Auto-generated method stub
          ??String className,url,uid,pwd;
          ???? className = "oracle.jdbc.driver.OracleDriver";
          ???? url?????? = "jdbc:oracle:thin:@172.16.5.135:1521:oratest";
          ???? uid?????? = "cyts_user";
          ???? pwd?????? = "1";
          ???? Class.forName(className);
          ???? Connection cn = DriverManager.getConnection(url,uid,pwd);
          ???? String sql="select customer_name from customer_info";
          ???? Statement sm = cn.createStatement();
          ???? ResultSet rs=sm.executeQuery(sql);
          ???? if(rs.next()){
          ???? ?System.out.println(rs.getString(1));
          ???? ?String old=rs.getString(1);
          ???? ?String newStr = new String(old.getBytes("ISO8859_1"), "GB2312");
          ???? ?System.out.println(newStr);
          ???? }
          ?}
          ?
          }

          很簡單,單如經(jīng)常忘,呵呵,都是這么多orm 讓我變得建忘了

          posted on 2006-07-05 11:59 康文 閱讀(222) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          <2006年7月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 龙陵县| 区。| 西吉县| 玉溪市| 慈利县| 荣成市| 响水县| 咸丰县| 油尖旺区| 古浪县| 三明市| 惠来县| 巴中市| 宜宾县| 丹寨县| 竹溪县| 正阳县| 时尚| 巧家县| 新宁县| 乐平市| 宣化县| 新干县| 安新县| 琼海市| 锦州市| 北碚区| 林口县| 璧山县| 嘉荫县| 年辖:市辖区| 醴陵市| 方山县| 蒙山县| 北川| 辽宁省| 平和县| 夏邑县| 福泉市| 伊吾县| 乃东县|