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. Android开发——Viewpager的介绍使用

    目录: 一.Viewpager的简单介绍 二.简单的Viewpager使用 三.简单显示图片的Viewpager实现 四.广告图的实现及Viewpager指示器(小圆点)的实现 五.APP引导页的实现 ...

  2. Could note find result map com.xxxx.entity.UserAccountDO

    原因: insert语句的标签写错:应该是parameterType,而不应该是resultType

  3. 序列化与transient

    满足下面四个条件中的一个的类就不应该被序列化:  1.一个类与本地代码(native code)有紧密的关系,如java.util.zip.Deflater,这个类中很多都是native的. 2.对象 ...

  4. 51NOD 1222 最小公倍数计数 [莫比乌斯反演 杜教筛]

    1222 最小公倍数计数 题意:求有多少数对\((a,b):a<b\)满足\(lcm(a,b) \in [1, n]\) \(n \le 10^{11}\) 卡内存! 枚举\(gcd, \fra ...

  5. nginx截获客户端请求

    使用nginx可以直接截获客户端请求,以下是最近收集的一些判断截获的信息的配置,为查看方便记录如下: 1.根据UA和cookie判断当前是移动端还是PC端访问: if ($http_host !~ & ...

  6. Asp.net core Razor 页面

    创建asp.net core 空项目->MyWeb 修改Startup.cs启动文件添加Razor页面支持: public void ConfigureServices(IServiceColl ...

  7. 携程Apollo(阿波罗)配置中心在.NET Core项目快速集成

    .NET Core的支持文档大体上可以参考文档.Net客户端使用指南:https://github.com/ctripcorp/apollo/wiki/.Net%E5%AE%A2%E6%88%B7%E ...

  8. GitLab的安装及使用教程

    1.配置yum源 vim /etc/yum.repos.d/gitlab-ce.repo 复制以下内容: [gitlab-ce] name=gitlab-ce baseurl=http://mirro ...

  9. python爬虫登录

    python3 urllib.request 网络请求操作 http://www.cnblogs.com/cocoajin/p/3679821.html python实现 爬取twitter用户姓名 ...

  10. 织梦去除版权中的Power by DedeCms

    找到文件 \include\dedesql.class.php 注释或删除下面代码,大概在588行 $arrs1 = array(0x63,0x66,0x67,0x5f,0x70,0x6f,0x77, ...