java.sql.SQLException:Column Index out of range,0<1
1、错误描述
java.sql.SQLException:Column Index out of range,0<1
2、错误原因
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
Statement stat = null;
ResultSet rs = null;
try
{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "root");
stat = conn.createStatement();
rs = stat.executeQuery(" select * from teacher ");
while(rs.next())
{
System.out.println(rs.getInt(0)+"-----"+rs.getString(1)+"-----"+rs.getInt(2)+"-----"+rs.getString(3));
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
由于rs.next()遍历查询结果时,下标是从“1”开始,而这里打印是从“0”开始,导致出错
3、解决办法
将遍历打印“System.out.println(rs.getInt(0)+"-----"+rs.getString(1)+"-----"+rs.getInt(2)+"-----"+rs.getString(3));”修改为“System.out.println(rs.getInt(1)+"-----"+rs.getString(2)+"-----"+rs.getInt(3)+"-----"+rs.getString(4));”
java.sql.SQLException:Column Index out of range,0<1的更多相关文章
- java.sql.SQLException: Parameter index out of range (0 < 1 ).
向SQL中传入数据是从1开始的!!! 从ResultSet中取数据也是从1开始的!
- Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0
1.错误描述 [ERROR:]2015-05-05 16:35:50,664 [异常拦截] org.hibernate.exception.GenericJDBCException: error ex ...
- java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2). java. ...
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at co ...
- 【Mybatis异常】Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
一.错误原因分析 从错误提示可以看出:实际传入的参数大于sql中待设置的参数,也就是sql中的?少于参数或?根本没有产生原因: ?号被单引号包围 如: sql += " and artic ...
- resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found.
resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found. 代码: String sql="SELECT d.co ...
- ibatis 更改resultmap后 java.sql.SQLException: Column 'del_status' not found.
当在resultmap中增加字段后,查询语句也必须增加相应字段,否则会报错, java.sql.SQLException: Column 'del_status' not found. 因为查询结果与 ...
- java.sql.SQLException:Column count doesn't match value count at row 1
1.错误描述 java.sql.SQLException:Column count doesn't match value count at row 1 2.错误原因 在插入数据时,插入的字段 ...
- java.io.IOException: java.sql.SQLException: ORA-01502: index 'BTO.PK_xxxxx' or partition of such index is in unusable state
最近由于数据库的全备出问题了,所以一直在观察. 刚好发现很多不需要的数据,就删了几百个G的数据吧. 今天突然就报这个问题. java.io.IOException: java.sql.SQLExcep ...
随机推荐
- java HotSpot 内存管理白皮书
原文见:http://www.open-open.com/lib/view/open1381034220705.html.查阅资料后,对原文做了补充. 文中关于JVM的介绍基于JDK1.6的Hotsp ...
- 整理一点与排列组合有关的问题[组合数 Stirling数 Catalan数]
都是数学题 思维最重要,什么什么数都没用,DP直接乱搞(雾.. 参考LH课件,以及资料:http://daybreakcx.is-programmer.com/posts/17315.html 做到有 ...
- MySQL Community Server 5.7安装详细步骤
mysql社区版安装配置步骤较繁琐,几经搜索之后才成功安装,此文将所有的安装步骤及安装过程中遇到的问题进行了总结 1. 下载MySQL社区版 最新版下载地址:https://dev.mysql ...
- zookeeper 内部机制学习
zookeeper 内部机制学习 1. zk的设计目标 最终一致性:client不论连接到那个Server,展示给它的都是同一个视图. 可靠性:具有简单.健壮.良好的性能.如果消息m被到一台服务器接收 ...
- PLECS—晶闸管-第九周
1. 单相桥式晶闸管整流电路仿真 (1)仿真电路图 (2)触发角为pi/4的手工波形图(参数设置,触发角=pi/4, 电感L = 0H) (2)模拟仿真波形图 1)参数设置:触发角=pi/4, 电感L ...
- dig挖出DNS的秘密
[最简单的dig用法] 最简单的dig用法,当然就是直接输入dig按回车. 1 2 3 4 5 6 $ dig ; <<>> DiG 9.8.2rc1-RedHat-9.8 ...
- 揽货最短路径解决方案算法 - C# 蚁群优化算法实现
需求为(自己编的,非实际项目): 某配送中心进行揽货,目标客户数为50个客户,配送中心目前的运力资源如下: 现有车辆5台 单台运力最大行驶距离200千米 单台运力最大载重公斤1吨 问:运力怎样走法才能 ...
- window 下生成NodeJs(v8.9.3) 的 VS2015 解决方案node.sln
window 下生成NodeJs(v8.9.3) 的 VS2015 解决方案node.sln 使用步骤 也可以参照 github: https://github.com/nodejs/node/blo ...
- Node.js 基础介绍(一)
Node.js 学习笔记一) 简单介绍--名称 Node.js,平时听到有好几种叫法,node .Node.js.nodejs ,但是比较正式的称呼还是"Node.js",由于它是 ...
- c中const定义的问题
/* 这题有个疑问: const double BASE1=BREAK1*RATE1; //第二个分界点前总共要缴的税收 const double BASE2=BASE1+(BREAK2-BREAK1 ...