开发者

Not Able to give previleges...Openoffice error

This is the code i had written to save the data into the openoffice database. but its giving 开发者_Python百科error.i m not understanding y it is appearing.

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



    }

}

This is the error..I m getting it when i trying to save the data into the database Can any one plz tell me where i m wrong.

Thank you.

run:

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)


Your connection URL looks iffy... try changing:

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

to

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

(adding a colon after "file", and appending the ifexists=true flag, as indicated by: http://hsqldb.org/doc/guide/ch04.html


It looks to me like the AGENCY_MASTER table doesn't exist. You're trying to execute an update statement, and it looks like HSQLDB can't find the AGENCY_MASTER table.

You can check whether the table exists with HSQLDB's built-in client/viewer:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜