不能给予特权...... Openoffice错误

时间:2009-12-24 08:38:05

标签: java

这是我编写的用于将数据保存到openoffice数据库的代码。 但它给出了错误。我不明白它出现了。

package coop.data;
import java.sql.*;
/**
 *
 * @author spk
 */
public class Connectionsetting {

    private static Connection con;

    private static Statement sm;

    private static ResultSet rs;

    public static void close()
    {
        try
        {
            sm.close();
            con.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public void connection() {
       String db_file_name_prefix = "/home/spk/Desktop/CooperHr/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");
            con=DriverManager.getConnection("jdbc:hsqldb:file"+db_file_name_prefix,"sa", "");
            System.out.println("Connection Eshtablished");
           // con.setAutoCommit(false);
            sm=con.createStatement();
       // sm = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
        } catch (Exception e) {
           e.printStackTrace();
        }
    }

    public static int executeupdate(String query) {
        //Execute & update block insert, update, delete statements
        int bool = 0;
        try {
                bool=sm.executeUpdate(query);
            } 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;
       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+")";
       cn.executeupdate(query);



    }

}

这是错误..我在尝试将数据保存到数据库时得到它 任何人都可以告诉我哪里错了。

谢谢。

运行:

Driver Found
Connection Eshtablished
java.sql.SQLException: user lacks privilege or object not found: AGENCY_MASTER
        at org.hsqldb.jdbc.Util.sqlException(Util.java:200)
        at org.hsqldb.jdbc.JDBCStatement.fetchResult(JDBCStatement.java:1805)
        at org.hsqldb.jdbc.JDBCStatement.executeUpdate(JDBCStatement.java:205)
        at coop.data.Connectionsetting.executeupdate(Connectionsetting.java:52)
        at coop.data.Connectionsetting.main(Connectionsetting.java:116)
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: AGENCY_MASTER
        at org.hsqldb.Error.error(Error.java:76)
        at org.hsqldb.SchemaManager.getTable(SchemaManager.java:510)
        at org.hsqldb.ParserDQL.readTableName(ParserDQL.java:4367)
        at org.hsqldb.ParserDML.compileInsertStatement(ParserDML.java:64)
        at org.hsqldb.ParserCommand.compilePart(ParserCommand.java:132)
        at org.hsqldb.ParserCommand.compileStatements(ParserCommand.java:83)
        at org.hsqldb.Session.executeDirectStatement(Session.java:1037)
        at org.hsqldb.Session.execute(Session.java:865)
        at org.hsqldb.jdbc.JDBCStatement.fetchResult(JDBCStatement.java:1797)
        ... 3 more
BUILD SUCCESSFUL (total time: 0 seconds)

2 个答案:

答案 0 :(得分:1)

您的连接网址似乎...尝试更改:

con=DriverManager.getConnection("jdbc:hsqldb:file"+db_file_name_prefix,"sa", "");

con=DriverManager.getConnection("jdbc:hsqldb:file:"+db_file_name_prefix+";ifexists=true","sa", "");

(在“file”之后添加一个冒号,并附加ifexists = true标志,如下所示:http://hsqldb.org/doc/guide/ch04.html

答案 1 :(得分:1)

在我看来,AGENCY_MASTER表不存在。您正在尝试执行update语句,看起来HSQLDB找不到AGENCY_MASTER表。

您可以检查该表是否与HSQLDB的内置客户端/查看器一起存在:

java -cp hsqldb.jar org.hsqldb.util.DatabaseManagerSwing