I have 2 column in my teams table id and teamname
this is my method
public List<String> getallteams() {
Connection conn = null;
ArrayList users = new ArrayList();
List<String> teams = new ArrayList();
try {
conn = DBConnection.openConnection();
String sql = " SELECT * FROM teams ";
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
String t1 = rs.getString(1);
String t2 = rs.getString(2);
String t3 = rs.getString(3);
String t4 = rs.getString(4);
String t5 = rs.getString(5);
String t6 = rs.getString(6);
String[] finalresult1 = {t1,t2,t3,t4,t5,t6 };
teams = Arrays.asList(finalresult1);
System.out.println(teams.get(1));
}
} catch (SQLException ex) {
Logger.getLogger(UsersDaoImp.class.getName()).log(Level.SEVERE, null, ex);
} finally {
DBConnection.closeConnection(conn);
}
return teams;
}
I'm new to mysqli, so struggling a bit here
but it give me java.sql.SQLException: Column Index out of range, 2 > 1 error