1

My problem is that I am trying to make a connection using Java (using Eclipse) to a local database. I don't want to use a remote database because I dont want to setup a server and also because my aplication doesn't need a remote DB.

I dont'have Microsoft Access, so I created the database using LibreOffice. What I know is that LibreOffice is the interface that allows you to create a database, and it can be set up using another database infrastructure like Oracle, MySQL, SQL Server, etc.

I decided to download the driver HSQLDB.jar and I installed it in Eclipse.

The following code shows you my example:

   String db="C:\\Users\\Alberto\\Documents\\Peluqueria.odb";

    try {  
        // Cargamos el controlador JDBC  
        Class.forName("org.hsqldb.jdbcDriver");  
    } catch (Exception ex){  
        System.err.println("Se pa producido un error al cargar el controlador JDBC");  
        return;  
    }  

    // Nos conectamos a la base de datos creándola en caso de que no exista   
    Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:"+db,"sa",""); 

    Statement statement=conn.createStatement();

    ResultSet rs=statement.executeQuery("SELECT * FROM TB_Servicios");

    while (rs.next()){
        System.out.println(rs.getString(1));
    }

The Error Exception i get is:

java.sql.SQLSyntaxErrorException: usuario no tiene privilegios suficientes o objeto no encontrado: TB_SERVICIOS
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.executeQuery(Unknown Source)
at Formularios.VentantaTabla.<init>(VentantaTabla.java:69)
at Formularios.VentantaTabla$1.run(VentantaTabla.java:31)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
     Caused by: org.hsqldb.HsqlException: usuario no tiene privilegios suficientes o
     objeto no encontrado: TB_SERVICIOS
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SchemaManager.getTable(Unknown Source)
at org.hsqldb.ParserDQL.readTableName(Unknown Source)
at org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source)
at org.hsqldb.ParserDQL.XreadTableReference(Unknown Source)
at org.hsqldb.ParserDQL.XreadFromClause(Unknown Source)
at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 18 more

Can anybody help me?

4

3 回答 3

1

您尚未使用 LibreOffice 完成数据库创建部分。

在 LibreOffice 中创建数据库后,您需要通过运行直接语句导出数据库的脚本SCRIPT 'file_path_name.script'。然后你从你的程序连接到jdbc:hsqldb:file:file_path_name

您不能.odb直接连接到文件。

于 2013-09-10T00:40:24.887 回答
0

好吧,我不懂西班牙语,但我翻译了您日志文件中的错误消息

usuario no tiene privilegios suficientes o objeto no encontrado

如下:

用户没有足够的权限或找不到对象

现在我们可以准确理解错误消息的内容了。您要么没有从表中选择的权限,TB_Servicios要么该表不存在。由于您使用的是用户帐户sa(即“系统管理员”)并且您的连接已成功建立,我可以假设您拥有所需的所有权限。因此,唯一的一种可能是您的数据库中不存在该表。

你创建表了TB_Servicios吗?如果不检查如何在您的数据库手册中创建它。祝你好运。

于 2013-09-09T18:47:08.967 回答
-1

感谢你们所有人,但最后我找到了解决方案。问题是当我使用 OpenOffice 创建数据库时,该文件的扩展名为“.odb”,并且该文件被压缩。

因此,如果我想连接到数据库,我必须先解压缩文件,然后我必须使用正确的驱动程序来建立连接。

希望对你有帮助

于 2013-09-13T14:16:23.623 回答