prepareStatement和resultSet的角标越界问题
之前一直做的android开发,数据库是sqlite,突然有需求要用到jdbc,在查询mysql数据库的时候除了一个问题,死活解决不了。报的是0<1,我当时想,0<1不是很正确吗?报这个错是闹哪样?
然后我看了下java的api,才明白sqlite的cursor拿数据和jdbc是不同的,cursor拿数据从0开始,而jdbc的prepareStatement和resultSet都是从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
相关推荐
Java连接达梦数据库驱动dm_jdbc: dm_jdbc\com.dameng.floader.jar dm_jdbc\com.dameng.impexp.jar dm_jdbc\Dm7Dictionary.jar dm_jdbc\Dm7JdbcDriver14.jar dm_jdbc\Dm7JdbcDriver15.jar dm_jdbc\Dm7JdbcDriver16....
Access_JDBC30.jar解决 1.破解仅支持连续查询50次和1000行的限制; 2.修复原版jar包使用execute()和executeUpdate()方法报空指针异常的BUG。
1.破解仅支持连续查询50次和1000行的限制; 2.修复原版jar包使用execute()和executeUpdate()方法报空指针异常的BUG。
原来使用Spring Boot 1.x版本,升级2.x之后,报如下异常: ### Cause: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName. at org.mybatis.spring.MyBatisExceptionTranslator....
一个是微软提供(msbase.jar mssqlserver.jar msutil.jar)另外一个是开源组织提供(jtds-1.2.4.jar),两中都可以用JDBC正常连接和使用,本人使用经验告诉我前一种和Hibernate JPA有写不兼容,经常报出异常。...
你是不是在连接数据库的时候会报出数据库的异常呢,你是不是会找不到错误呢,也许你少了驱动!
这个东西非常诡异,我用两个Excel测试一个能读,一个却报出SQL异常,说Table找不到,目前只可以排除数据多少和有无汉字的原因。不过老实说,看到要加一堆jar进去才能用的时候我就决定放弃它了,只是顺手试试而已。
1 1Java的诞生 1 2Java的特点 1 3安装Sun公司的SDK 1 4一个Java程序的开发过程 1 5一个简单的Java应用程序的开发过程 1 6一个简单的Java小应用程序 1 7什么是JSP 习题 第2章标识符 关键字和数据类型 2 1标识符和...
怀疑canal没有配置好,检查canal的日志后发现异常: 2020-02-15 10:58:24.506 [destination = example , address = /192.168.0.105:3306 , EventParser] ERROR ...
第1章 Java语言概述1.1 Java语言简介 1.2 Java语言特点 1.3 Java程序开发 第2章 Java语言基础 2.1 符号集 2.2 数据类型 2.3 常量与变量 2.4 运算符与表达式 2.5 数组 第3章 流程控制结构 3.1 流程控制结构...
在一次部署中,总是连不上数据库,报一些网络异常,路由不到的问题,oracle 11g 建议使用oracle.jdbc.OracleDriver类,不建议使用oracle.jdbc.driver.OracleDriver,改了好了 连接类型: 1、JDBC OCI: oci...
误报异常,就是无法显示数据库表中的数据,或者修 改和删除数据不成功。本文是笔者根据多年Java教学 经验,对Java访问SQL Server数据库的三种方式: JDBC—ODBC桥连接、纯Java方式连接~lWebLogic 数据库连接池连接...
D) 在Java中布尔值可以用true或false来表示,但是同时也可以用1或0来表示。 题目5:b 程序如下: class Test { public static void main(String[] args) { int i=1000; for(;;) { if(i>999) { ...
描述:非空无默认值的Datetime类型字段,查询时程序报以下错误: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp 解决方法:数据库连接串添加zeroDateTimeBehavior参数或者...
如果直接往采用utf-8编码的数据库中插入表情数据,Java程序中将报SQL异常: java.sql.SQLException: Incorrect string value: ‘\xF0\x9F\x92\x94’ for column ‘name’ at row 1 at ...
简介: 该软件是我毕业时候做的一个毕业设计。并且获得了优秀毕业设计的奖项...注意: 本软件采取JAVA JDBC纯驱动连接方式。 使用前必须有驱动包!!!! 注意:该资源来自www.qoovod.com,如需转载,请保留此信息。
第1章 初识Java 3 1.1 Java简介 3 1.1.1 Java的不同平台 3 1.1.2 Java发展的历程 3 1.1.3 Java的特点 4 1.2 安装开发工具包 5 1.2.1 下载JDK 5 1.2.2 安装JDK 6 1.2.3 安装后Java目录的解读 7 1.3...
且支持各种Telemetry数据流支持对Telemetry数据流的异常检测和基于规则实时告警通过预设时间使用Hadoop存储Telemetry的数据流支持使用ElasticSearch实现自动化实时索引Telemetry数据流支持使用Hive利用SQL查询存储在...
实例1 HelloWorld 实例10 创建一个窗体 实例100 上传文件 实例11 按扭 实例12 复选框 实例13 复合下拉列表 实例14 下拉列表 实例15 选项卡 实例16 对话框 实例17 文件对话框 实例18 使用HTML语言 实例19 菜单 实例2 ...
BSF 集成并封装Apollo,Rocket MQ,Redis, Elastic Search,ELK,XXL-JOB, Sharding JDBC,Cat,Eureka,七牛云,Swagger等第三方中间件,标准化使用规范,并集成了自研的监控报警,用来监控各个服务系统的性能及异常告警,提供...