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

发布于 2024-08-16 08:14:03 字数 4955 浏览 3 评论 0原文

## 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);


    }

}

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

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
## 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);


    }

}

But its again giving this error..
can any one tell me where i m wrong.the database is open office base..
thanx

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冧九 2024-08-23 08:14:04

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

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

可以直接参考HSQL文档

You certainly haven't loaded the HSQL database in your application classpath and your connection string does not look right.

Add the HSQL database driver jar found in openoffice lib directory and follow this post.

You can refer directly to the HSQL documentation

醉生梦死 2024-08-23 08:14:04
由以下原因引起:java.lang.ClassNotFoundException:在 gnu.gcj.runtime.SystemClassLoader 中找不到 java.sql.Wrapper

众所周知,GNU JDK 存在缺陷。摆脱 GNU JDK 并安装 Sun JDK

也就是说,您的 JDBC 代码写得不好。它不是线程安全的,并且存在潜在的资源泄漏。您应该在方法块中声明所有外部资源,并且确保不要将其声明为静态变量。您应该在同一个 try/finally 块中获取和关闭资源。要了解如何正确执行 JDBC,您可以找到 这篇文章很有用。

Caused by: java.lang.ClassNotFoundException: java.sql.Wrapper not found in gnu.gcj.runtime.SystemClassLoader

GNU JDK is known to be buggy. Get rid of GNU JDK and install Sun JDK.

That said, your JDBC code is poorly written. It is not threadsafe and has potential resource leaks. You should declare all external resources in a method block and for sure not as a static variable. You should acquire and close resources in the very same try/finally block. To get an idea how to do the JDBC properly, you may find this article useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文