Java.sql.SQLException:Column Index out of range,0<1

Source: Internet
Author: User

1. Error description

Java.sql.SQLException:Column Index out of range,0<1


2. Cause of Error

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 ();}

Since Rs.next () traverses the query results, the subscript starts with "1", where printing starts with "0", causing an error


3. Solutions

Will traverse the print "System.out.println (rs.getint (0) +"-----"+rs.getstring (1) +"-----"+rs.getint (2) +"-----"+rs.getstring (3));" Modified to "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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.