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的更多相关文章

  1. java.sql.SQLException: Parameter index out of range (0 < 1 ).

    向SQL中传入数据是从1开始的!!! 从ResultSet中取数据也是从1开始的!

  2. 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 ...

  3. 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. ...

  4. 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 ...

  5. 【Mybatis异常】Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

    一.错误原因分析 从错误提示可以看出:实际传入的参数大于sql中待设置的参数,也就是sql中的?少于参数或?根本没有产生原因:  ?号被单引号包围 如: sql += " and artic ...

  6. resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found.

    resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found. 代码: String sql="SELECT d.co ...

  7. ibatis 更改resultmap后 java.sql.SQLException: Column 'del_status' not found.

    当在resultmap中增加字段后,查询语句也必须增加相应字段,否则会报错, java.sql.SQLException: Column 'del_status' not found. 因为查询结果与 ...

  8. 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.错误原因     在插入数据时,插入的字段 ...

  9. 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 ...

随机推荐

  1. 【机器学习实战 第九章】树回归 CART算法的原理与实现 - python3

    本文来自<机器学习实战>(Peter Harrington)第九章"树回归"部分,代码使用python3.5,并在jupyter notebook环境中测试通过,推荐c ...

  2. Laravel 5.4.36 session 没有保存成功问题

    session使用注意点 工作中使用的是session默认的文件缓存  在使用过发现  session()->put("key","values")  发 ...

  3. 终于放弃Windows下丑陋的cmd

    微软万年不变的cmd命令行工具,简直其丑无比,交互性极差.但是作为开发者有时离不开.最近用了几款开源替代方案.发现几款不错的cmd替代者.例如Cmder.babun.ConsoleZ.win-bash ...

  4. BZOJ 3569: DZY Loves Chinese II [高斯消元XOR 神题]

    http://www.lydsy.com/JudgeOnline/problem.php?id=3569 题意:多次询问一个无向连通图当图中某k条边消失时这个图是否联通 强制在线 太神啦啦啦啦啦啦啦啦 ...

  5. 创建hbase-indexer出现 0 running

    新建hbase-indexer后通过hbase-indexer list-indexers发现SEP subscription ID: null并且0 running processes,如下: IN ...

  6. new day

    Learning English is so long,but my english still is not good.I hope that one day I can speak english ...

  7. [Python Study Notes]进程信息(丁丁软件监控进程,http-post)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  8. 金融&业务常识积累

    前言 在项目中遇到很多名词,不太明白其含义.这些名词都是和金融领域紧密相关并且与项目的业务有着直接的联系.因此,决定通过搜集资料和归纳总结,对经后的工作产生一定的帮助. 常见的金融知识 PDL: Pa ...

  9. Linux-安装FFmpeg

    FFmpeg官网:http://www.ffmpeg.org 官网介绍 FFmpeg is the leading multimedia framework, able to decode, enco ...

  10. bzoj 1171 大sz的游戏& 2892 强袭作战 (线段树+单调队列+永久性flag)

    大sz的游戏 Time Limit: 50 Sec  Memory Limit: 357 MBSubmit: 536  Solved: 143[Submit][Status][Discuss] Des ...