- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在执行 SQL 插入时将标识列返回给我的 java 程序。运行代码时出现以下错误
Uncaught exception thrown in one of the service methods of the
servlet: Cocoon. Exception thrown : java.lang.AbstractMethodError: java/sql
/Connection.prepareStatement(Ljava/lang/String;I)Ljava/sql/PreparedStatement;
这是我正在运行的代码。
private void insertUserInputParameters(ReportData rptData){
UserInputParameters userParams = rptData.getUserInputData();
StringBuilder sql = new StringBuilder();
PreparedStatement pstmt = null;
ResultSet rs = null;
int userDataId = -1;
//Get a database connection.
sl = ServiceLocator.getInstance();
ds = sl.getDataSource("jdbc/collegeguide");
con = ds.getConnection();
con.setReadOnly(false);
sql.append("insert into cpgusrdtaf (statecd, addr1, addr2, city, state, ");
sql.append("zipcode, dependent, shdindic, marstatus, residency, prntatge, ");
sql.append("fincome, mincome, pincome, taxspaid, taxreturn, elig1040, ");
sql.append("gincome, pcash, inetwrth, bnetwrth, pbenefit, paddlinf, ");
sql.append("puntax, pdslcwrk, smstatus, sresidncy, studtr, stud1040, ");
sql.append("sadjinc, sincome, spincome, sdslcwrk, studtax, scash, ");
sql.append("sinvest, snetwrth, saddlinf, suntax, househld, nmbrsch, ");
sql.append("studact, studsat, schools, housing) ");
sql.append("values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ");
sql.append("?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
//This line of code is where I get the error**
pstmt = con.prepareStatement(sql.toString(), Statement.RETURN_GENERATED_KEYS);
//If I remove the 'Statement.RETURN_GENERATED_KEYS' I do not get the error.**
pstmt = con.prepareStatement(sql.toString());
setStatementValues(pstmt, userParams);
pstmt.executeUpdate();
rs = pstmt.getGeneratedKeys();
if(rs.next()){
userDataId = rs.getInt(1);
}
我不允许使用存储过程,所以我不能走那条路。任何帮助将不胜感激
我正在使用 java 1.5
提前致谢道格
最佳答案
假设参数/参数是平衡的
(请确认查询在 native 执行,并且驱动程序支持 RETURN_GENERATED_KEYS),
您可以尝试使用 RETURN_GENERATED_KEYS 作为 executeUpdate 调用的参数的一部分吗?
pstmt = con.createStatement();
pstmt.executeUpdate(sql.toString(), Statement.RETURN_GENERATED_KEYS);
编辑:只需阅读您关于使用 DB2 的说明。根据http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.apdv.java.doc%2Fsrc%2Ftpc%2Fimjcc_t0057053.html
_Restriction:对于 IBM Data Server Driver for JDBC and SQLJ version 3.57 或更高版本,以下形式对于将行插入 DB2® for z/OS® 数据服务器上的 View 无效。
Connection.prepareStatement(sql语句, 声明.RETURN_GENERATED_KEYS);_
关于Java PreparedStatement RETURN_GENERATED_KEYS 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11105815/
我有一个简单的问题。我的代码中有一些内存泄漏,因为我认为这是因为 PreparedStatement 和 ResultSet 我想知道释放资源及其内存的最佳、安全和正确的方法是什么。 Prepared
package jdbcDemo; import java.sql.*; public class PreparedStatement { public static void mai
服务器端和客户端上的语句缓存是通过 PreparedStatement 的字符串呈现严格缓存还是其他什么?换句话说,如果两个不同的 PreparedStatement 是通过不同的方式创建的,但最终具
我对 C++ Mysql 连接器有“一点”问题。我想使用 PreparedStatement。我尝试了文档中的示例 http://dev.mysql.com/doc/refman/5.1/en/con
我已经将 JAVA 应用程序与 MySql 连接起来。当我编写 PreparedStatement ps = null ;然后显示导入包的两个选项。两个建议的包是:com.mysql.jdbc.Pre
PreparedStatement setString 取一个“null”(就像 String a = "null"),在 .addBatch 之后它被转换成一个普通的 null(就像 String
我正在使用 PreparedStatement 的 setString 方法在 sql 查询中设置开始日期和结束日期的值。 String sql = "..... " AND tableA.time
这个问题已经有答案了: Using Prepared Statements to set Table Name (8 个回答) 已关闭 5 年前。 我正在尝试使用准备好的语句创建一个新表,但收到错误
使用 SQL 的最佳解决方法是什么 IN具有 java.sql.PreparedStatement 实例的子句,由于 SQL 注入(inject)攻击安全问题,不支持多个值:1 ?占位符代表一个值,而
我正在开发一个使用PreparedStatement的java应用程序。 SELECT FIELD1, FIELD2 FROM MYTABLE WHERE (FIELD1='firstFieldVal
我正在使用PreparedStatements写入数据库,有时我会在日志中看到以下内容: 2015-02-02 15:44:14,601 WARN SQL Warning Code: 1292,
query = "SELECT * FROM POST_COMMENT WHERE Post_date_time= ? AND Post_User= !;"; query = query.r
有没有一种方法可以在 php 准备好的语句中设置字段名称,而不是仅仅设置那里的值,例如, $stmt = $mysqli->prepare("UPDATE movies SET filmName =
我对“同时使用 Java 和 SQL”这整个事情还很陌生,我似乎找不到解决这个问题的方法。我通过 Workbench 在服务器上创建了一个数据库,现在我正在使用它的 Netbeans 创建一个简单的应
我对这样的准备好的语句有疑问: select ... from ... where xy = ? and foo = ? and bla = ? 我可以为每个索引设置一个字符串吗?否则我不得不做 pr
我有一个多线程代码的工作版本,但是我对我的 PreparedStatement-wrapper 类是非线程安全的感到不满意。所以我决定在 ThreadLocal 中生成 PreparedStateme
当使用 JDBC 的 PreparedStatements 查询 Oracle 时,请考虑: String qry1 = "SELECT col1 FROM table1 WHERE rownum=?
使用 SQL 的最佳解决方法是什么 IN具有 java.sql.PreparedStatement 实例的子句,由于 SQL 注入(inject)攻击安全问题,不支持多个值:1 ?占位符代表一个值,而
使用 SQL 的最佳解决方法是什么 IN具有 java.sql.PreparedStatement 实例的子句,由于 SQL 注入(inject)攻击安全问题,不支持多个值:1 ?占位符代表一个值,而
使用 SQL 的最佳解决方法是什么 IN具有 java.sql.PreparedStatement 实例的子句,由于 SQL 注入(inject)攻击安全问题,不支持多个值:1 ?占位符代表一个值,而
我是一名优秀的程序员,十分优秀!