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. c#监测电脑状态

    public class DeviceMonitor { static readonly PerformanceCounter cpuCounter = new PerformanceCounter( ...

  2. Jquery DataTable控制显示列,导出EXCEL

    1.初始化 var table = $('#table').DataTable({ "data": data[0].DATA, "columns": data[ ...

  3. BZOJ 1856: [Scoi2010]字符串 [Catalan数]

    1856: [Scoi2010]字符串 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1418  Solved: 790[Submit][Status][ ...

  4. BZOJ 2754: [SCOI2012]喵星球上的点名 [后缀数组+暴力]

    2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1906  Solved: 839[Submit][St ...

  5. ASP.NET Core 入门

    关于ASP.NET Core ASP.NET Core 是一个全新的开源.跨平台框架,可以用它来构建基于网络连接的现代云应用程序,比如:Web 应用,IoT(Internet Of Things,物联 ...

  6. C#实现航班查询及预订

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  7. Windows Server 2016-部署RODC只读域控制器

    只读域控制器Read-Only Domain Controller简称RODC.RODC是Windows Server 2008之后引入的一活动目录特性,与其他域控制器一样包含AD数据库,但RODC默 ...

  8. Java并发系列[5]----ReentrantLock源码分析

    在Java5.0之前,协调对共享对象的访问可以使用的机制只有synchronized和volatile.我们知道synchronized关键字实现了内置锁,而volatile关键字保证了多线程的内存可 ...

  9. Linux中7个用来浏览网页和下载文件的命令

    上一篇文章中,我们提到了rTorrent.wget.cURL.w3m.Elinks等几个有用的工具,很多人回信说还有其它几个类似的工具也值得讨论,所以就有了这篇文章.如果错过了第一部分的讨论,可以通过 ...

  10. map,vector 等容器内容的循环删除问题(C++)

    map,vector 等容器内容的循环删除问题(C++) map,vector等容器的循环删除不能用普通的方法删除: for(auto p=list.begin();p!=list.end();p++ ...