JDBC第一篇

------------------------------------------------------oracle-jdbc-------------------------------------------------------------

1、oracle-jdbc基础

驱动: oracle.jdbc.driver.OracleDriver

url:jdbc:oracle:thin:@//<host>:<port>/ServiceName或jdbc:oracle:thin:@<host>:<port>:<SID>

备注:sid是对内的称呼,处于实例级别;而service name是对外的称呼,是数据库级别

代码示例:

将下面的示例代码中的驱动和url更换成oracle格式即可!

------------------------------------------------------mysql-jdbc-------------------------------------------------------------

2、mysql-jdbc基础

驱动:com.mysql.jdbc.Driver

url:jdbc:mysql://localhost:3306/数据库名称?useUnicode=true&characterEncoding=utf-8

备注:mysql的数据库名称-mysql实例:eg:mysql,test等以及自己创建的数据库

代码示例:

引自:http://hzy3774.iteye.com/blog/1689525
public class DBHelper {  
    public static final String url = "jdbc:mysql://127.0.0.1/student";  
    public static final String name = "com.mysql.jdbc.Driver";  
    public static final String user = "root";  
    public static final String password = "root";  
  
    public Connection conn = null;  
    public PreparedStatement pst = null;  
  
    public DBHelper(String sql) {  
        try {  
            Class.forName(name);//指定连接类型  
            conn = DriverManager.getConnection(url, user, password);//获取连接  
            pst = conn.prepareStatement(sql);//准备执行语句  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  
  
    public void close() {  
        try {  
            this.conn.close();  
            this.pst.close();  
        } catch (SQLException e) {  
            e.printStackTrace();  
        }  
    }  
}  

 

------------------------------------------------------资源列表-------------------------------------------------------------

mysql-jdbc

http://elf8848.iteye.com/blog/1684414

以下还没来得及细看

http://developer.51cto.com/art/200907/137300.htm

http://www.blogjava.net/chunkyo/archive/2007/01/16/94266.html

 

 

猜你喜欢

转载自lbovinl.iteye.com/blog/2172791