Connecting to a database
In order to access a database, you need to obtain a JDBC
Connection
object. There are two basic ways to get a database connection:Using the JDBC
DriverManager
interface, you can directly obtain a JDBCConnection
, if you know:
- The name of the JDBC Driver class (
com.quadcap.jdbc.JdbcDriver
)- The database URL (
jdbc:qed:database-name
)- Any connection parameters (see below)
For QED, you could obtain a database connection using code similar to the following:
//获得驱动,建立连接
Class.forName("com.quadcap.jdbc.JdbcDriver"); java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:qed:mydb");//mydb是要连接的数据库名称or, to create a new database:
//创建一个新的数据库
Class.forName("com.quadcap.jdbc.JdbcDriver"); java.util.Properties p = new java.util.Properties(); p.setProperty("create", "true"); java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:qed:mynewdb", p);another way to create a new database:
//另外一种创建数据库的方法
Class.forName("com.quadcap.jdbc.JdbcDriver"); java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:qed:mynewdb;create=true");