Java连接sql终止查询命令,为什么我得到这个“SQLSyntaxErrorException:ORA-00933:SQL命令未正确结束”当我尝试执行此JDBC查询时?...

I have some problem trying to implement a simple JDBC query into a Java application.

So I have the following query:

SELECT D.*

FROM coda_tx c, documenti_tx d

WHERE C.FK_TIPO_DOC = 99

AND C.FK_STATO = 1

AND C.FK_PIVA_MITTENTE = '05779711000'

AND C.PK_CODA = D.PFK_CODA

AND C.CANALE='STA'

If I run it into Oracle SQL Developer it run well and I obtain 2 records as result.

So I have to implement this query into a DAO class of my application in which I definied the following method:

public void getListaFatturePDF(String partitaIva) {

System.out.println("INTO ottieniListaFatturePDF()");

Blob blobPdf;

String sql;

StringBuffer sb = new StringBuffer();

sb.append("SELECT D.*");

sb.append("FROM coda_tx c, documenti_tx d");

sb.append("WHERE C.FK_TIPO_DOC = 99");

sb.append("AND C.FK_STATO = 1");

sb.append("AND C.PK_CODA = D.PFK_CODA");

sb.append("AND C.CANALE='STA'");

sb.append("AND C.FK_PIVA_MITTENTE = '");

sb.append(partitaIva);

sb.append("';");

sql = sb.toString();

try {

statment = connection.createStatement();

ResultSet rs = statment.executeQuery(sql);

System.out.println("ResultSet obtained");

} catch (SQLException e) {

e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.

}

}

The problem is that when I try to perform the previous method is thrown the following SQLException:

java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)

at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059)

at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)

at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)

at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587)

at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:210)

at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:30)

at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:762)

at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:925)

at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1111)

at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1309)

at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:422)

at DAO.FatturaDAO.getListaFatturePDF(FatturaDAO.java:43)

at mainPkg.Main.main(Main.java:74)

Why? I think that maybe is something wrong in the SQL syntax but I am not sure about it (because if I perform the query into Oracle SQL Developer it works fine) What am I missing? How can I fix it?

Tnx

解决方案

executeQuery() automatically adds a semicolon to a statement when executing it.

Change the line sb.append("';"); to sb.append("'");.

Also you'll need to add spaces at the end or at the beginning of each line, your statements are invalid otherwise.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值