0

How can I create a connector for Pervasive PSQL in Java?

How can I create a connector for Pervasive PSQL? I created a sample connector, but I am not sure whether it is right or wrong.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Navyah
  • 1,660
  • 10
  • 33
  • 58
  • Are you having a problem with the code posted? If so, what is it? What version of Pervasive are you using? – mirtheil May 07 '12 at 11:22
  • java.lang.NuSuchMethodError: main when i running the code, i can find it is run time exception but, i am not able to find what next i need to do, i am using pervasive version 10 – Navyah May 07 '12 at 12:37

2 Answers2

7

Here's a simple program I have that works for me to connect to a Pervasive PSQL database:

/*
 * SQLStatement.java
 * Simple JDBC Sample using Pervasive JDBC driver.
 */
import java.*;
import java.sql.*;
import pervasive.jdbc.*;
import java.io.*;


public class SQLStatement {

    public static void main(String args[]) {

        String url = "jdbc:pervasive://localhost:1583/demodata?transport=tcp";
        Connection con;

        String query = "select* from class";
        Statement stmt;

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

        } catch(Exception e) {
            System.err.print("ClassNotFoundException: ");
            System.out.println(e.toString());
            System.err.println(e.getMessage());
        }

        try {
            Connection conn = DriverManager.getConnection(url);

            stmt = conn.createStatement();

            ResultSet rs = stmt.executeQuery(query);
            ResultSetMetaData rsmd = rs.getMetaData();
            int numberOfColumns = rsmd.getColumnCount();
            int rowCount = 1;
            long j = 0;
            int i = 1;

            while (rs.next()) {
                System.out.println("Row " + rowCount + ":  ");
                for (i = 1; i <= numberOfColumns; i++) {
                    System.out.print("   Column " + i + ":  ");
                    System.out.println(rs.getString(i));
                }
                System.out.println("");
                rowCount++;
            }

            System.out.println("Waiting.");
            String thisLine;
            try {
                InputStreamReader converter = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(converter);
                while ((thisLine = br.readLine()) != null) { // while loop begins here
                    System.out.println(thisLine);
                } // end while
            } // end try
            catch (IOException e) {
                System.err.println("Error: " + e);
            }

            stmt.close();
            conn.close();

        } catch(SQLException ex) {
            System.err.print("SQLException: ");
            System.err.println(ex.getMessage());
        }
    }
}

To compile it, I use:

javac -classpath "C:\Program Files\Pervasive Software\PSQL\bin\pvjdbc2.jar";"C:\Program Files\Pervasive Software\PSQL\bin\pvjdbc2x.jar";"C:\Program Files\Pervasive Software\PSQL\bin\jpscs.jar";. SQLStatement.java

And to run it, I use:

java -classpath "C:\Program Files\Pervasive Software\PSQL\bin\pvjdbc2.jar";"C:\Program Files\Pervasive Software\PSQL\bin\pvjdbc2x.jar";"C:\Program Files\Pervasive Software\PSQL\bin\jpscs.jar";.\ SQLStatement.java

You might need to change the location of the PSQL JAR files if you are using a 64-bit OS.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mirtheil
  • 8,952
  • 1
  • 30
  • 29
0

I use the following library with Dbeaver for querying in a Pervasive database:

  • jpscs.jar
  • pvjdbc2x.jar
  • pvjdbc2.jar
halfer
  • 19,824
  • 17
  • 99
  • 186