Search code examples
javahibernatepervasivepervasive-sql

Pervasive SQL Java Database Name


EDIT: I also tried the standard java connection using this answer: Creating Java Connector for pervasive

the main problem here is that it works with Demodata, but the name of the database I need to use use ° in the name: GESCOOP°2018

I'm not sure that is the problem but I know that I only get this error:

SQLException: [LNA][PSQL][SQL Engine][Data Record Manager]Cannot locate the named database you specified(Btrieve Error 2301)

for database with ° in the name.

Original question:

I need to use a Pervasive ODBC database with Hibernate (if possible, if not I need to use it inside java). I already got 3 files: jpscs.jar pvjdbc2.jar pvjdbc2x.jar that should be the JDBC drivers for pervasive DB but I don't know how to create an hibernate config file with this dialect (I'm not sure hibernate support pervasive and I'm not sure if possible to configure custom sql db).

I was just able to configure a Pervasive 32-bit ODBC Client DNS setup (with windows configure data source on control panel) with a simple Server Name (no account or password). And the connection test is successful but I don't know how to view tables and data of this db.

Current hibernate config file hibernate.cfg.xml:

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>

    <property name = "hibernate.dialect">
     org.hibernate.dialect.
    </property>

    <property name = "hibernate.connection.driver_class">
     com.pervasive.jdbc.v2.Driver
    </property>

    <!-- Assume test is the database name -->

    <property name = "hibernate.connection.url">
     GBJOB09.GBJOB.LOCAL/GESCOOP*2018
    </property>

    <!-- List of XML mapping files -->
    <!-- mapping resource = "Employee.hbm.xml"/ -->

 </session-factory>
</hibernate-configuration>

Solution

  • In the end I used C# with this code:

    string conn = "Provider=PervasiveOLEDB;  Data Source=gescoop°2018;Location=<url>";
    string queryString = "select * from TAB_UTENTI";
    
    try
    {
        using (OleDbConnection connection = new OleDbConnection(conn))
        {
            OleDbCommand command = new OleDbCommand(queryString, connection);
            connection.Open();
            OleDbDataReader reader = command.ExecuteReader();
    
            while (reader.Read())
            {
                Debug.WriteLine(reader.GetValue(0).ToString() + "  " +
                    reader.GetValue(1).ToString() + "  " +
                    ...
                    reader.GetValue(47).ToString() + "  ");
            }
            reader.Close();
        }
    }
    catch (Exception ex)
    {
        Debug.WriteLine("Failed to connect to data source " + ex.Message);
    }
    

    I think there is some limitation with jdbc driver on java that does not allow special characters like ° in the database name. I cannot change the database name so my only way is to use C#.