Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

cn database connect

redraiment edited this page Jun 4, 2014 · 2 revisions

jActiveRecord通过DB.open静态方法连接数据库,参数与java.sql.DriverManager#getConnection兼容。成功连接后返回me.zzp.ar.DB类;否则抛出me.zzp.ar.ex.DBOpenException异常。

  • open(String url):试图建立到给定数据库URL的连接。
  • open(String url, String username, String password):试图建立到给定数据库URL、用户名和密码的连接。
  • open(String url, Properties info):根据给定参数信息,试图建立到给定数据库URL的连接。

注意 这三个方法在内部都仅创建一个连接对象,因此能正常使用内存型数据库;在真实项目中推荐使用C3P0等数据库连接池,以获得更好的性能!

DB sqlite3 = DB.open("jdbc:sqlite::memory:");
DB postgresql = DB.open("jdbc:postgresql:test", "postgres", "password");
DB mysql = DB.open("jdbc:mysql://localhost/test", new Properties());
Clone this wiki locally