gpt4 book ai didi

java - 为 Pervasive PSQL 创建 Java 连接器

转载 作者:行者123 更新时间:2023-12-01 07:37:01 26 4
gpt4 key购买 nike

如何为 Pervasive PSQL 创建连接器在Java 中?

如何为 Pervasive PSQL 创建连接器?我创建了一个示例连接器,但我不确定它是对还是错。

最佳答案

这是一个简单的程序,可以让我连接到 Pervasive PSQL数据库:

/*
* 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 文件的位置。

关于java - 为 Pervasive PSQL 创建 Java 连接器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10477378/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com