Java 开放式office数据库中的查询

Java 开放式office数据库中的查询,java,openoffice.org,Java,Openoffice.org,我正在使用OpenOfficeDatabase3.3作为我的数据库。我能够成功建立连接,但在尝试执行查询时出错: public class openofficeupdate { String databaseurl="C:\\Users\\RAVITEJA\\Documents\\BluetoothExchangeFolder\\salesforce.odb"; openofficeupdate() throws ClassNotFoundException, SQLException{

我正在使用OpenOfficeDatabase3.3作为我的数据库。我能够成功建立连接,但在尝试执行查询时出错:

 public class openofficeupdate {
String databaseurl="C:\\Users\\RAVITEJA\\Documents\\BluetoothExchangeFolder\\salesforce.odb";
openofficeupdate() throws ClassNotFoundException, SQLException{
    System.out.println("Entered into constructor");
    Connection connection=null;
    Statement statement=null;
   try{
    Class c=openofficeclass();
    System.out.println("Class name set");

    Connection cntn=createConnection(databaseurl);
    connection=cntn;
    System.out.println("connection created");

    Statement stmt=createStatement(cntn);
    statement=stmt;
    System.out.println("Statement created");

    executeQueries(stmt);
    System.out.println("Query executed");

    closeStatement(stmt);
    System.out.println("Statement closed");

    closeConnection(cntn);
    System.out.println("Connection closed");

    }catch(Exception e){
        System.out.println(e);

        closeStatement(statement);
        System.out.println("Statement closed");

        closeConnection(connection);
        System.out.println("Connection closed");
    }
}
public static void main(String args[]) throws ClassNotFoundException, SQLException{
    new openofficeupdate();
}

private Class openofficeclass() throws ClassNotFoundException {
    return Class.forName("org.hsqldb.jdbcDriver");
}

private Connection createConnection(String databaseurl) throws SQLException{
    return DriverManager.getConnection("jdbc:hsqldb:file:" +databaseurl);
}

private Statement createStatement(Connection cntn) throws SQLException{
    return cntn.createStatement();
}

private void closeStatement(Statement stmt) throws SQLException{
    stmt.close();
}

private void closeConnection(Connection cntn) throws SQLException{
    cntn.close();
}

private void executeQueries(Statement stmt) throws SQLException{

    System.out.println("Going to execute query");
    //int status=stmt.executeUpdate("insert into Mobiles(Mobile ID,Employee ID,Start_Track_Time,Stop_Track_Time) values(987654321,198,09:30:00,10:30:00)");
    ResultSet rs=stmt.executeQuery("select * from Mobiles;");
    while(rs.next()){
        System.out.println("Inside row "+rs.getRowId(1));
    }
    System.out.println("Query executed with status ");
}
}
我将hsqldb.jar设置为我的类路径。上述代码的输出显示为

Entered into constructor
Class name set
connection created
Statement created
Going to execute query
java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: MOBILES
Statement closed
Connection closed

这有什么问题?

当您连接到数据库时,您是作为一个没有权限访问数据库中某个实体的用户进行连接的。您需要将您的连接用户设置为具有适当权限的用户。根据这一点,您需要的用户名是SA

当数据库开发人员得知OpenOffice.org Base已经有了一个用户帐户时,可能会感到惊讶。此用户帐户(名为SA)


使用Connection对象上的方法将用户名设置为“SA”。

Thank you@Kurtis Nusbaum,但是如何在open office数据库中为用户设置适当的权限。您从哪个软件包获取连接类?这将帮助我决定如何更好地回答您;对于sql连接和查询,我发现一些默认情况下开放式office数据库为只读。。我们应该使用sql手动创建一个用户。我尝试了这个,但是查询没有执行。。。。。。。。。创建用户sfts密码跟踪系统管理员您可以发布您正在阅读的OO文档的链接吗?