-
Notifications
You must be signed in to change notification settings - Fork 7
en database connect
redraiment edited this page Jun 4, 2014
·
2 revisions
jActiveRecord
provides DB.open
static method, which parameters are compatible with java.sql.DriverManager#getConnection
, to connect database. Returns me.zzp.ar.DB
instance if success; otherwise, throw a me.zzp.ar.ex.DBOpenException
exception.
-
open(String url)
: Attempts to establish a connection to the given database URL. -
open(String url, String username, String password)
: Attempts to establish a connection to the given database URL with username and password. -
open(String url, Properties info)
: Attempts to establish a connection to the given database URL with connection information.
Note above three methods would create an inner database connection only, so that works with in-memory database well; While should use C3P0 pooled connection for better performance in real project.
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());
- 博客:zzp.me
- 微博:@redraiment