Getting primary key information from Pervasive SQL
807591May 14 2008 — edited May 14 2008I am doing a project in which I have to get the primary key information of a Table at run time. I have to do this task in both SQL Server and Pervasive SQL Databases. I found a function getPrimaryKeys() to do this task. The problem is that this function is giving results in the SQL Server Database but its not giving any result in the Pervasive SQL Database. I have debuged the following code and in case of Pervasive the getPrimaryKeys() method is returning empty ResultSet.
import java.sql.*;
public class Main {
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newI nstance();
Connection db_connection =
DriverManager.getConnection ("jdbc:odbc:MQAUPDT", "", "");
Statement db_statement = db_connection.createStatement();
String tableName = "GPRCCODE";
ResultSet rs = null;
DatabaseMetaData meta = db_connection.getMetaData();
rs = meta.getPrimaryKeys(null, null, tableName);
while (rs.next())
{
System.out.println(rs.getString("COLUMN_NAME"));
}
rs.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Can anyone tell me that whether this method works for Pervasive or not? And if this method doesn't work with Pervasive then whats the alternate way of doing the same thing.
Waiting for the reply and thanks in advance.