首页 > 数据库技术 > 详细

jdbc报0<1异常

时间:2015-01-22 02:19:21      阅读:279      评论:0      收藏:0      [点我收藏+]

prepareStatementresultSet的角标越界问题

?

?

之前一直做的android开发,数据库是sqlite,突然有需求要用到jdbc,在查询mysql数据库的时候除了一个问题,死活解决不了。报的是0<1,我当时想,0<1不是很正确吗?报这个错是闹哪样?

?

然后我看了下javaapi,才明白sqlitecursor拿数据和jdbc是不同的,cursor拿数据从0开始,而jdbcprepareStatementresultSet都是从1开始的,附上证据:

?

void?java.sql.PreparedStatement.setObject(int parameterIndex,?Object?x) throwsSQLException



Sets the value of the designated parameter using the given object. The second parameter must be of type?Object; therefore, the?java.lang?equivalent objects should be used for built-in types.

The JDBC specification specifies a standard mapping from Java?Object?types to SQL types. The given argument will be converted to the corresponding SQL type before being sent to the database.

Note that this method may be used to pass datatabase- specific abstract data types, by using a driver-specific Java type. If the object is of a class implementing the interface?SQLData, the JDBC driver should call the method?SQLData.writeSQL?to write it to the SQL data stream. If, on the other hand, the object is of a class implementing?Ref,?Blob,?Clob,?NClob,?Struct,?java.net.URL,RowId,?SQLXML?or?Array, the driver should pass it to the database as a value of the corresponding SQL type.

Note:?Not all databases allow for a non-typed Null to be sent to the backend. For maximum portability, the?setNull?or the?setObject(int parameterIndex, Object x, int sqlType)method should be used instead of?setObject(int parameterIndex, Object x).

Note:?This method throws an exception if there is an ambiguity, for example, if the object is of a class implementing more than one of the interfaces named above.

Parameters:parameterIndex?the first parameter is 1, the second is 2, ...x?the object containing the input parameter valueThrows:SQLException?- if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs; this method is called on a closedPreparedStatement?or the type of the given object is ambiguous

?

?

?

void?java.sql.PreparedStatement.setObject(int parameterIndex,?Object?x) throwsSQLException



Sets the value of the designated parameter using the given object. The second parameter must be of type?Object; therefore, the?java.lang?equivalent objects should be used for built-in types.

The JDBC specification specifies a standard mapping from Java?Object?types to SQL types. The given argument will be converted to the corresponding SQL type before being sent to the database.

Note that this method may be used to pass datatabase- specific abstract data types, by using a driver-specific Java type. If the object is of a class implementing the interface?SQLData, the JDBC driver should call the method?SQLData.writeSQL?to write it to the SQL data stream. If, on the other hand, the object is of a class implementing?Ref,?Blob,?Clob,?NClob,?Struct,?java.net.URL,RowId,?SQLXML?or?Array, the driver should pass it to the database as a value of the corresponding SQL type.

Note:?Not all databases allow for a non-typed Null to be sent to the backend. For maximum portability, the?setNull?or the?setObject(int parameterIndex, Object x, int sqlType)method should be used instead of?setObject(int parameterIndex, Object x).

Note:?This method throws an exception if there is an ambiguity, for example, if the object is of a class implementing more than one of the interfaces named above.

Parameters:parameterIndex?the first parameter is 1, the second is 2, ...x?the object containing the input parameter valueThrows:SQLException?- if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs; this method is called on a closedPreparedStatement?or the type of the given object is ambiguous

?

?

jdbc报0<1异常

原文:http://zhonglunshun.iteye.com/blog/2178176

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!