經常忘的jdbc數據庫連接

          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);
          ???? }
          ?}
          ?
          }

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

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


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


          網站導航:
           
          <2006年7月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 澄城县| 老河口市| 深水埗区| 鹿泉市| 嘉善县| 阳山县| 南溪县| 泸溪县| 舒城县| 丰台区| 乐业县| 凤台县| 西贡区| 河南省| 灯塔市| 阳朔县| 石嘴山市| 潼关县| 嘉兴市| 阳原县| 绥德县| 汾西县| 吉林市| 鹿邑县| 衡东县| 曲水县| 平乡县| 苍梧县| 四子王旗| 普陀区| 深州市| 敖汉旗| 文水县| 萨嘎县| 自治县| 新密市| 昆山市| 新河县| 高州市| 汾阳市| 鲜城|