经常忘的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 康文 阅读(208) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2006年7月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜