相关疑难解决方法(0)

在postgres jdbc驱动程序中记录准备好的sql语句

我想在我的java应用程序中记录所有准备好的sql语句.我正在使用标准的postgres jdbc驱动程序org.postgresql.Driver.该驱动程序有一个名为"loglevel"的参数,可以设置为1(INFO)或2(DEBUG).关键是如果参数设置为1,它几乎不记录任何内容,如果设置为2,它的跟踪太多了

...
20:59:05.608 (2)  FE=> Bind(stmt=null,portal=null,$1=<'5'>,$2=<'13'>)
20:59:05.609 (2)  FE=> Describe(portal=null)
20:59:05.609 (2)  FE=> Execute(portal=null,limit=1)  
20:59:05.609 (2)  FE=> Sync
20:59:05.648 (2)  <=BE ParseComplete [null]
20:59:05.649 (2)  <=BE BindComplete [null]
20:59:05.649 (2)  <=BE NoData
20:59:05.649 (2)  <=BE CommandStatus(UPDATE 1)
...
Run Code Online (Sandbox Code Playgroud)

有没有办法只记录语句+参数?

java postgresql jdbc

7
推荐指数
1
解决办法
3826
查看次数

我们可以在预准备语句(PostgreSQL)中使用DDL命令吗?

DDL 命令如下:

CREATE TABLE - 使用用户提供的列名创建一个表.

DROP TABLE - 删除所有行并从数据库中删除表定义.

ALTER TABLE - 从表中添加或删除列.

如果有可能在PostgreSQL和Java中使用这些命令,我​​需要几个例子吗?

public boolean create(Employee employee) {

    try {

        callableStatement = openConnection().prepareCall("{call insert_employee(?,?,?)}");
        callableStatement.setInt(1, employee.getEid());
        callableStatement.setString(2, employee.getEname());
        callableStatement.setInt(3, employee.getSid());     

        i = callableStatement.execute();

        callableStatement.close();

        closeConnection();



    } catch (SQLException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return i;

}
Run Code Online (Sandbox Code Playgroud)

有没有机会在这种类型中使用DDL CREATE命令?用准备好的陈述?

java postgresql ddl jdbc java-ee

6
推荐指数
2
解决办法
3846
查看次数

标签 统计

java ×2

jdbc ×2

postgresql ×2

ddl ×1

java-ee ×1