Java 技术篇 - java同时连接多种数据库执行sql语句的兼容性验证,数据库类型包括:oraclesqlserverDB2人大金仓达梦PG瀚高polardb

Posted 挣扎的蓝藻

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java 技术篇 - java同时连接多种数据库执行sql语句的兼容性验证,数据库类型包括:oraclesqlserverDB2人大金仓达梦PG瀚高polardb相关的知识,希望对你有一定的参考价值。

第一章:数据库测试

①【 oracle 数据库不支持分号】ORA-00933: SQL 命令未正确结束


报错:OriginalSql = delete from org_reportcombinestru where code = '报表合并体系2';, Error Msg = ORA-00933: SQL 命令未正确结束

java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束

	at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:509)
	at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:461)
	at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1104)
	at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:550)
	at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:268)
	at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:655)
	at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:229)
	at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:41)
	at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:928)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1205)
	at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1747)
	at oracle.jdbc.driver.OracleStatement.executeLargeUpdate(OracleStatement.java:1712)
	at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1699)
	at oracle.jdbc.driver.OracleStatementWrapper.executeUpdate(OracleStatementWrapper.java:285)
	at com.dbmanage.db.DBUpdate.getRs(DBUpdate.java:21)
	at com.dbmanage.db.DBMain.update_sql(DBMain.java:57)
	at com.dbmanage.db.ReadFile.getFileContent(ReadFile.java:28)
	at com.dbmanage.db.ReadClipboard.lostOwnership(ReadClipboard.java:87)
	at sun.awt.datatransfer.SunClipboard.lostOwnershipNow(SunClipboard.java:313)
	at sun.awt.datatransfer.SunClipboard.lambda$lostOwnershipLater$0(SunClipboard.java:283)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: Error : 933, Position : 68, Sql = delete from org_reportcombinestru where code = '报表合并体系1';, OriginalSql = delete from org_reportcombinestru where code = '报表合并体系1';, Error Msg = ORA-00933: SQL 命令未正确结束
	at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:513)
	... 33 more

② 【sqlserver 数据库不支持 commit】COMMIT TRANSACTION 请求没有对应的 BEGIN TRANSACTION

sqlservser 数据库测试

报错:com.microsoft.sqlserver.jdbc.SQLServerException: COMMIT TRANSACTION 请求没有对应的 BEGIN TRANSACTION

com.microsoft.sqlserver.jdbc.SQLServerException: COMMIT TRANSACTION 请求没有对应的 BEGIN TRANSACTION。
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:254)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1608)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:859)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:759)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7240)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2869)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:243)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:218)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:706)
	at com.dbmanage.db.DBUpdate.getRs(DBUpdate.java:21)
	at com.dbmanage.db.DBMain.update_sql(DBMain.java:87)
	at com.dbmanage.db.ReadFile.getFileContent(ReadFile.java:28)
	at com.dbmanage.db.ReadClipboard.lostOwnership(ReadClipboard.java:87)
	at sun.awt.datatransfer.SunClipboard.lostOwnershipNow(SunClipboard.java:313)
	at sun.awt.datatransfer.SunClipboard.lambda$lostOwnershipLater$0(SunClipboard.java:283)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

③ 【DB2 数据库不支持分号】SQLSTATE=42601, SQLERRMC=;;de = ‘报表合并体系1’;END-OF-STATEMENT

db2 数据库测试

报错:com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=;;de = '报表合并体系1';END-OF-STATEMENT, DRIVER=4.19.49

com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=;;de = '报表合并体系1';END-OF-STATEMENT, DRIVER=4.19.49
	at com.ibm.db2.jcc.am.kd.a(Unknown Source)
	at com.ibm.db2.jcc.am.kd.a(Unknown Source)
	at com.ibm.db2.jcc.am.kd.a(Unknown Source)
	at com.ibm.db2.jcc.am.fp.c(Unknown Source)
	at com.ibm.db2.jcc.am.fp.d(Unknown Source)
	at com.ibm.db2.jcc.am.fp.b(Unknown Source)
	at com.ibm.db2.jcc.t4.bb.i(Unknown Source)
	at com.ibm.db2.jcc.t4.bb.c(Unknown Source)
	at com.ibm.db2.jcc.t4.p.b(Unknown Source)
	at com.ibm.db2.jcc.t4.vb.h(Unknown Source)
	at com.ibm.db2.jcc.am.fp.jb(Unknown Source)
	at com.ibm.db2.jcc.am.fp.a(Unknown Source)
	at com.ibm.db2.jcc.am.fp.c(Unknown Source)
	at com.ibm.db2.jcc.am.fp.executeUpdate(Unknown Source)
	at com.dbmanage.db.DBUpdate.getRs(DBUpdate.java:21)
	at com.dbmanage.db.DBMain.update_sql(DBMain.java:88)
	at com.dbmanage.db.ReadFile.getFileContent(ReadFile.java:28)
	at com.dbmanage.db.ReadClipboard.lostOwnership(ReadClipboard.java:87)
	at sun.awt.datatransfer.SunClipboard.lostOwnershipNow(SunClipboard.java:313)
	at sun.awt.datatransfer.SunClipboard.lambda$lostOwnershipLater$0(SunClipboard.java:283)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

④ 【kingbase 人大金仓数据库没问题】

⑤ 【DM 达梦数据库没问题】

⑥ 【PG、瀚高数据库没问题】

⑦ 【polardb 数据库没问题】

第二章:测试环境

① 测试 sql 语句

形式如下面的语句以及在此基础上的嵌套 sql 语句:

insert into org_xxx (a, b, c, ...) values (a1, b1, c1, ...);
commit;
delete from org_xxx where code = 'xxx';
commit;
update org_xxx set name = "xxx" where code = 'xxx';
commit;

② 测试代码块

外部调用下面的代码来执行。

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUpdate {

    public static int getRs(Connection conn, String sql) {
        /*
        作用:插入、更新、删除数据库
        返回:影响的行数:0代表无影响
        */
        Statement st = null;
        int rs = 0;

        try {
            // statement对象用于执行sql语句
            st = conn.createStatement(以上是关于Java 技术篇 - java同时连接多种数据库执行sql语句的兼容性验证,数据库类型包括:oraclesqlserverDB2人大金仓达梦PG瀚高polardb的主要内容,如果未能解决你的问题,请参考以下文章

JDBC是啥

Java异常处理

java数据库连接池技术原理

JDBC入门

Java 泛型机制

用java如何实现以多种条件进行查找?例如,只比较姓名,查找姓李的人,查找某年出生的,等等