经常忘的jdbc数据库连接

经常忘的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 让我变得建忘了



你可能感兴趣的:(经常忘的jdbc数据库连接)