gpt4 book ai didi

java - 打开 Office 数据库错误(运行时显示异常)

转载 作者:行者123 更新时间:2023-12-01 16:08:48 25 4
gpt4 key购买 nike

## This is the code i m runnig in linux ubuntu.. ##
import java.sql.*;
/**
*
* @author spk
*/
public class Connectionsetting {

private static Connection con;

private static java.sql.Statement sm;

private static ResultSet rs;

public void close()
{
try
{
sm.close();
con.close();
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}
public void connection() {
String db_file_name_prefix = "/home/spk/Desktop/database/mydb.odb";
/*
If required change the file name if you are working in windows os
connection is in work

*/
try {
Class.forName("org.hsqldb.jdbcDriver");
System.out.println("Driver Found");
}
catch(ClassNotFoundException e){
System.out.println(e.getMessage());
}
try {
//con=DriverManager.getConnection("jdbc:hsqldb:file"+db_file_name_prefix,"sa", "");
con=DriverManager.getConnection("jdbc:hsqldb:file:"+db_file_name_prefix,"", "");
System.out.println("Connection Eshtablished");


sm=con.createStatement();
// sm = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}

public static int executeupdate(String query) {
//Execute & update block insert, update, delete statements
int bool = 0;
try {
bool=sm.executeUpdate(query);
con.commit();
} catch (Exception e) {
e.printStackTrace();
}

return bool;
}

public ResultSet executeQuery(String query) {
//Block Returns single resultset,,,sql statements such as sql select
ResultSet rs=null;
try {
rs = sm.executeQuery(query);
} catch (Exception e) {
e.printStackTrace();
}
return rs;
}
public boolean checkTableStatus(String tblName) {
String sql = "selec * from cat";

ResultSet rs=null;

boolean status = false;

int i = 0;

String allTableNames[] = new String[20];
try {
connection();
rs = sm.executeQuery(sql);
while (rs.next()) {

allTableNames[i] = rs.getString(0);
i++;

if (allTableNames[i].equals(tblName)) {
status = true;
break;
} else {
status = false;
break;
}
}

} catch (Exception e) {
e.printStackTrace();
}
return status;
}
public static void main(String []args)
{
String query,s1,s2,s3,s4,s5,s6,s7,s8;
int i=0;
Connectionsetting cn=new Connectionsetting();
cn.connection();
s1="same";
s2="sam";
s3="923847";
s4="sam";
s5="sam";
s6="sam";
s7="sam";
s8="R01";
query="insert into Agency_Master values("+s1+","+s2+","+s3+","+s4+","+s5+","+s6+","+s7+","+s8+")";
i=cn.executeupdate(query);

System.out.println(i);


}

}

但它再次给出这个错误..谁能告诉我哪里错了。数据库是开放办公基地..感谢x

Driver Found
Exception in thread "main" java.lang.NoClassDefFoundError: org.hsqldb.jdbc.JDBCConnection
at java.lang.Class.initializeClass(libgcj.so.90)
at org.hsqldb.jdbc.JDBCDriver.getConnection(JDBCDriver.java:285)
at org.hsqldb.jdbc.JDBCDriver.connect(JDBCDriver.java:245)
at java.sql.DriverManager.getConnection(libgcj.so.90)
at java.sql.DriverManager.getConnection(libgcj.so.90)
at Connectionsetting.connection(Connectionsetting.java:45)
at Connectionsetting.main(Connectionsetting.java:116)
Caused by: java.lang.ClassNotFoundException: java.sql.Wrapper not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/home/COOPERENG/spk/workspace/Test/,file:/home/COOPERENG/spk/workspace/hsqldb.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.90)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.VMClassLoader.defineClass(libgcj.so.90)
at java.lang.ClassLoader.defineClass(libgcj.so.90)
at java.security.SecureClassLoader.defineClass(libgcj.so.90)
at java.net.URLClassLoader.findClass(libgcj.so.90)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.Class.forName(libgcj.so.90)
at java.lang.Class.initializeClass(libgcj.so.90)
...6 more

最佳答案

您肯定没有在应用程序类路径中加载 HSQL 数据库,并且您的连接字符串看起来不正确。

添加在 openoffice lib 目录中找到的 HSQL 数据库驱动程序 jar 并按照此 post 操作.

可以直接引用HSQL documentation

关于java - 打开 Office 数据库错误(运行时显示异常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1968042/

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