|
附录A : 使用JDBC 驱动器连接AS/400 数据库
你可以使用DriverManager.getConnection() 方法来连接AS/400数据库. DriverManager.getConnection() 使用一个URL字符串作为参数. JDBC驱动器管理器将为尝试连接在URL字符串中所指的数据库:
"jdbc:as400://systemName/defaultSchema;listOfProperties"
以下是一些连接方式的例子
例一:URL不给出系统名。这种情况需要用户在使用时给出欲连接的系统名:
"jdbc:as400:"
例二:URL只给出系统名
Connection c = DriverManager.getConnection("jdbc:as400://mySystem");
例三:URL给出系统名,且给出缺省的Schema
Connection c2 = DriverManager.getConnection("jdbc:as400://mySys2/mySchema");
例四:连接AS/400 数据库,且使用java.util.Properties 定义更多的JDBC 连接属性。
// Create a properties object.
Properties p = new Properties();
// Set the properties for the connection.
p.put("naming", "sql");
p.put("errors", "full");
// Connect using the properties object.
Connection c = DriverManager.getConnection("jdbc:as400://mySystem",p);
例五:连接AS/400数据库,并且给出URL的相关属性.
// Connect using properties. The properties are set on the URL
// instead of through a properties object.
Connection c = DriverManager.getConnection( "jdbc:as400://mySystem;naming=sql;errors=full");
例六:连接AS/400数据库且给出用户名与口令
// Connect using properties on the URL and specifying a user ID and password
Connection c = DriverManager.getConnection(
"jdbc:as400://mySystem;naming=sql;errors=full",
"auser", "apassword");
例七:关闭数据库连接
使用close() 方法将连接关闭,如 c.close();
|