PreviousJDBC Driver Guide (9.1 revision 1) Next

JDBC Programming Tasks

Show this topic in Library frames

This section highlights important concepts for JDBC programming.

Connection String Overview

The JDBC driver requires a URL to connect to a database. The syntax for URL for the Pervasive JDBC driver is :

jdbc:pervasive://<machinename>:<port number>/Datasource 
 

<machinename> is the host name or ip address of the machine that runs the Pervasive.SQL server

<portnumber> is the port on which the Pervasive.SQL server is listening - by default it is 1583

<datasource> is the name of the ODBC engine data source on the Pervasive.SQL server that the application intends to use.


Note
A Pervasive.SQL V8 engine needs to be running on the specified host in order to run JDBC applications.

The Pervasive JDBC driver now supports character encoding, which allows you to filter data you read through a specified code page so that it is formatted and sorted correctly.

Connection String Elements

The following shows how to connect to a Pervasive.SQL database using JDBC:

Driver Classpath

com.pervasive.jdbc.v2 

Statement to Load Driver

Class.forName("com.pervasive.jdbc.v2.Driver"); 

URL

jdbc:pervasive://server:port/DSN;encoding 
 

argument
description
server
Enter the server name using an ID or a URL.
port
Pervasive's relational engine default port is 1583. If no port is specified, the default is used.
DSN
Set up a DSN on the server using regular ODBC methods.
encoding

JDBC Connection String Example

The following code shows how to connect to a Pervasive database using the JDBC driver:

// Load the Pervasive.SQL JDBC driver 
Class.forName("com.pervasive.jdbc.v2.Driver") 
// Pervasive JDBC URL Syntax: 
// jdbc:pervasive://<hostname or ip address > : 
//   <port num (1583 by default)>/<odbc engine DSN> 
String myURL = "jdbc:pervasive://127.0.0.1:1583/
demodata"; 
 try 
    { 
// m_Connection = 
DriverManager.getConnection(myURL,username, 
password); 
} 
   catch(SQLException e) 
	{ 
		e.printStackTrace(); 
		// other exception handling 
         } 

Using Character Encoding

Character encoding is specified using a parameter in the connection string passed to the driver manager.

Encoding parameter allows user to specify the code page to be used for translating the string data stored in the database. The default system encoding is used if no encoding is explicitly specified.

Example of Using Character Encoding

public static void main(String[] args) 
{ 
	//specify latin 2 encoding 
	String url = "jdbc:pervasive://MYSERVR:1583/
SWEDISH_DB;encoding=cp850"; 
	try{ 
		
Class.forName("com.pervasive.jdbc.v2.Driver"); 
		Connection conn = 
DriverManager.getConnection(url); 
		Statement stmt = conn.createStatement(); 
		ResultSet rs = stmt.executeQuery("select * 
from SwedishTable"); 
		rs.close(); 
		stmt.close();					 
		conn.close(); 
	} 
	catch(Exception e) 
	{ 
		e.printStackTrace(); 
	} 
} 

Notes on Character Encoding


Chapter contents
Publication contents

Prev topic: Programming with the Pervasive JDBC 2 Driver
Next topic: Developing Web-based applications