These samples show how to use the solidDB JDBC driver to connect to a solidDB server, execute simple SQL queries, and use database procedures or BLOBs.
The files for the samples are located in the soliddb-installdir\samples\jdbc directory.
Note To run the samples, you must install JDK 1.7 or later and set the PATH and CLASSPATH settings for the Java compiler.
For general information about running the samples, see Samples.
The following samples are included:
▪ sample1.java: connects to solidDB and executes a simple SELECT statement and prints out some metadata from the query,
▪ sample3.java: a database procedure example that uses prepared statements,
▪ sample4.java: reads a binary file, saves the content in the database as a BLOB, and reads the BLOB from the database.
Running the samples
Run the runme script (runme.bat in Windows), which compiles the applications, starts a solidDB database, and then runs the applications one after the other.
Sample 1
The sample1 application completes the following actions:
1 Register the driver by using JDBC driver manager services.
2 Prompt the user for a valid JDBC connect string. The connect string format is: jdbc:solid://hostname:port/username/password
For example, the following string attempts to connect to a solidDB server on the same computer and listens to the TCP/IP protocol at port 2315:
jdbc:solid://localhost:2315/dba/dba
3 Connect to the solidDB database by using the driver.
4 Create the following statement to select data from a solidDB system table:
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE FROM TABLES
5 Execute the query.
6 Fetch and output all the rows of a result set.
7 Close the database connection.
Troubleshooting the sample1.java sample application
The following possible issues and their solutions might be experienced when you run the sample1.java sample application:
▪ Problem: The driver cannot be successfully registered.
Possible solutions:
– The Java environment does not support java.sql classes.
– SolidDriver2.0.jar is not in the CLASSPATH definition.
▪ Problem: Unable to connect to solidDB server.
Possible solutions:
– The version of the solidDB server should be 100 or later.
Older solidDB versions might refuse connections from the driver that is provided with the current release.
– The connect string might be wrong or solidDB might not be listening to the specified port.
Check that solidDB is running and verify the listening information. You can use, for example, solidDB SQL Editor (solsql) to ensure that a connection can be established through the network.
Sample 3
The sample3 application completes the following actions:
1 Register the driver by using JDBC driver manager services.
2 Prompt the user for a valid JDBC connect string.
3 Connect to the solidDB database by using the driver.
4 Drop and create the procedure sample3 (if the procedure does not exist, dump the related exception).
5 Call the procedure by using java.sql.Statement.
6 Fetch and output all the rows of a result set.
7 Close the database connection.
Sample 4
The sample4 application completes the following actions:
1 Register the driver by using JDBC driver manager services.
2 Prompt the user for a valid JDBC connect string.
3 Connect to the solidDB database by using the driver.
4 Drop and create a table sample4 (if the table does not exist, dump the related exception),
5 Insert the content of a binary file in the database as a BLOB file.