首页 > Berkeley DB, SQL, 赵汝聪 > Using DBSQL JDBC Driver in ADF/JDeveloper

Using DBSQL JDBC Driver in ADF/JDeveloper

2010年6月1日 赵汝聪

Oracle 应用程序开发框架 (Oracle ADF) 是一个端到端 J2EE 框架,该框架通过提供现成的基础架构服务和虚拟的声明式开发体验,从而简化了开发。JDeveloper是Oracle公司开发的Java集成开发环境(IDE)。本博客介绍了如何在ADF/JDeveloper中使用DBSQL作为JDBC数据库连接的引擎。

This guide describes how to apply DBSQL JDBC Driver in integrated development environment ADF/JDeveloper step by step.
Environment:

  • OS: Windows XP 32bit
  • ADF Business Components: 11.1.1.56.60
  • Java(TM) Platform: 1.6.0_18
  • JDeveloper: 11g Release 1(11.1.1.3.0)

1. Installing the Berkeley DB

  • Make sure that the Java environment you apply in the building should be the same as ADF/JDeveloper’s.
  • Refer to http://www.oracle.com/technology/documentation/berkeley-db/db/installation/build_win_sql.html for instructions about building JDBC Driver on Windows platform. The Release build option is recommended.
  • Add the dll path into system PATHenvironment variable, e.g. add D:\jdbc\db-5.0.21\build_windows\Win32\Release to your %PATH%

2. Create JDBC Connection in JDeveloper

2.1 Select File->new->General->Connections->Database Connection and fill in the form like Figure 1. Select button “new” to create new driver SQLiteJDBCDriver(see following Figure 2).
Figure 1

2.2 Create a new driver SQLiteJDBCDriver. You should back to Figure 1 after clicking button “OK”.
Figure 2

2.3 You can use button “Test Connection” to test the setting in Figure 1. If you encounter NullPointerException, please refer following section “Troubleshooting 4.1″

2.4 Create an empty project(or open an existing project). Select Edit->properties->Libraries Classpath to add the registered DBSQL_JDBC:
Figure 3

3. Running the JDBC Sample Code

This chapter only shows how to run the JDBC samples downloaded from Sun (now belongs to Oracle) Developer Network. You can skip this chapter if you already have a test environment.

3.1 Downloading JDBC sample code from Sun
You can download the JDBC sample code from Sun Developer Network. See “JDBC programming examples from all three editions (ZIP format)” at http://java.sun.com/products/jdbc/reference/codesamples/index.html.

3.2 Modifications Needed
Create an empty project and add all JDBC sample code into it. You will definitely need to:

  • Replace Class.forName(“myDriver.ClassName”) in all sample code files with Class.forName(“SQLite.JDBCDriver”)
  • Replace “jdbc:mySubprotocol:myDataSource” in all sample code files with jdbc:sqlite:/D:\\example.db
  • Change the variable name “enum” in OutputApplet.java to “enum1″, since as “enum” is a keyword in some Java environment, and may not be used as an identifier. Otherwise, you may encounter “Error(87,31): as of release 5, ‘enum’ is a keyword, and may not be used as an identifier”

3.3 Running examples

Example Name Depended Example Name
CreateCoffees None
InsertCoffees CreateCoffees
BatchUpdate CreateCoffees
InsertRow CreateCoffees
InsertRows CreateCoffees. This example has an issue: it should execute uprs.moveToInsertRow() before each uprs.insertRow().
RSMetaDataMethods CreateCoffees
TransactionPairs CreateCoffees
TypeConcurrency CreateCoffees
PrintColumns CreateCoffees(or InsertCoffees, or BatchUpdate)
OutputApplet CreateCoffees(or InsertCoffees, or BatchUpdate). This example also require AppletViewer environment.
CreateSuppliers None
InsertSuppliers CreateSuppliers
Join InsertCoffees(or BatchUpdate) and InsertSuppliers
SQLStatement InsertCoffees(or BatchUpdate) and InsertSuppliers
PrimaryKeysSuppliers None
ForeignKeysCoffees None
TypeInfo None
TableTypes None

Other examples does not work because BDSQL JDBC driver does not support User-defined type or something like that.

Take SQLStatement.java for example, since it depends on “InsertCoffees(or BatchUpdate) and InsertSuppliers”, further more, “InsertCoffees(or BatchUpdate)” again depends on “CreateCoffees”, and “InsertSuppliers” depends on “CreateSuppliers”, so one reasonable sequence to run the SQLStatement example looks like this:

Execute CreateCoffee.java
Execute CreateSuppliers.java
Execute InsertCoffee.java
Execute InsertSuppliers.java
Execute SQLStatement.java

Finally, we can get result like below:

Row 1:
   Column 1:  Acme, Inc.
   Column 2:  Colombian

Row 2:
   Column 1:  Acme, Inc.
   Column 2:  Colombian_Decaf

Process exited with exit code 0.

Here is a screenshot of the execution result of the SQLStatement
Figure 4

4. Troubleshooting

4.1 Edit db_sql_jdbc.vsproj for different JDK environemt
If you encounter one of following issues:

  • Encounter NullPointerException in JDeveloper JDBCconnection testing(figure 1)
  • Hits “ClassNotFoundException: SQLite.JDBC2x.JDBCConnection” when executing Java programs.

That means that your Java environment requires JDBC2x.* instead of JDBC2z.*. So you need to edit build_windows/ex_sql_jdbc.vcproj, replace all JDBC2z with JDBC2x and rebuild the project (ex_sql_jdbc.vcproj).

本文的评论功能被关闭了.
Դ