Top
Interstage Studio User's Guide
FUJITSU Software

8.3.8 Using the DB Access Class Wizard to Automatically Generate JDBC Processes

By using the DB access class wizard in the standard workbench, DB access processing using JDBC can be generated automatically as a DB access class.

DB access classes deploy search, insertion, deletion, and update processes as methods based on the information specified using the wizard, and deploy the processing target database columns as class fields. Thus, when a DB access class is used, DB access processes are performed by invoking methods while setting values in and fetching values from class fields.

Creating a DB access class

From the [New] wizard, select [Java] > [Source] > [DB Access Class] and use the wizard to create the DB access class. See below for the wizard settings.

Information

If the JDBC driver 2.x is being used, the connect method of the automatically generated class must be replaced with the following comment content that is coded in the same source:

// This is the connect method for JDBC2.x connections.
// Substitute this for the existing connect method and enter the required items. This enables access to be executed from a data source.
//public void connect(java.lang.String userName, java.lang.String passWord) throws javax.naming.NamingException, java.sql.SQLException {
//	//Connect to the database.
//	java.util.Hashtable env = new java.util.Hashtable();
//	env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "{ initial context factory}");
//	env.put(javax.naming.Context.PROVIDER_URL, "{provider URL}");
//	javax.naming.InitialContext ctx = new javax.naming.InitialContext(env);
//	javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("jdbc/{ data source name}");
//	con = ds.getConnection(userName, passWord);
//	con.setAutoCommit(true);
//}

When replacing the comment contents, also correct the coding for the database connection items below.

Item name

Coding example

Initial context factory

com.fujitsu.symfoware.jdbc2.jndisp.SYMContextFactory

(Register the JDBC driver in the project build path in advance.)

Provider URL

SYM://<connection destination address>:<port number>

Data source name

JDBC/<name registered by data source registration tool>