Home  >  Forum  >  Database
Post New Query

java.sql.SQLException: Invalid column index


joined on
February 03,2015
Asked on March 04,2015
I am creating JDBC program in which accessing result set from database, my code snippet is ...
public UserDTO getUserInfoByCh(int challan){
UserDTO userDTO = new UserDTO();
try {
PreparedStatement preStat = connection.prepareStatement("select CHALLAN, NAME, FNAME from user_form where CHALLAN = ?");
preStat.setInt(1, challan);
ResultSet result = preStat.executeQuery();
while(result.next()) {
userDTO.setChallan(result.getInt(0));
userDTO.setName(result.getString(1));
userDTO.setFname(result.getString(2));
}
} catch (SQLException e) {
e.printStackTrace();
}

And getting the exception as below..

java.sql.SQLException: Invalid column index
        at oracle.jdbc.driver.GeneratedScrollableResultSet.getInt(GeneratedScrol
lableResultSet.java:508)
        at com.hostelmanagement.dao.UserDAO.getUserInfoByCh(UserDAO.java:53)
        at com.hostelmanagement.servlet.UserInfoByChServlet.doGet(UserInfoByChSe
rvlet.java:26)
        at com.hostelmanagement.servlet.UserInfoByChServlet.doPost(UserInfoByChS
ervlet.java:18)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:291)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:505)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:142)
joined on
March 15,2013
Replied on March 04,2015

You need to start your index from 1 not to 0.

Write Answer



Sitewide-Feb4of4234x60





Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us