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