本文介绍了为普及创建Java连接器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以给我打电话,如何在java中创建一个普及的连接器。我是新手,从我需要开始我不确定,可以任何1请告诉我如何为pervasive.i创建连接器创建一个示例连接器,但我不确定它是对还是错
CAN any one please tel me, how to create a connector for pervasive in java. I am very new to this,from where i need t start i am not sure, can any1 please tell me how can i create a connector for pervasive.i created a sample connector , but i am not sure whether it is right or wrong
推荐答案
这是一个简单的程序,我可以连接到PSQL数据库:
Here's a simple program I have that works for me to connect to a 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());
}
}
}
为了编译它,我使用:
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
要运行它,我使用:
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
如果您使用的是64位操作系统,则可能需要更改PSQL JAR文件的位置。
You might need to change the location of the PSQL JAR files if you are using a 64-bit OS.
这篇关于为普及创建Java连接器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!