java - Its giving me an error saying Column not found -


its giving me error saying column not found

import java.sql.*; class jdbc_demo {     public static void main(string args[])     {         try         {             class.forname("sun.jdbc.odbc.jdbcodbcdriver");             connection con=drivermanager.getconnection("jdbc:odbc:testc");             //class.forname("com.mysql.jdbc.driver");             //connection con=drivermanager.getconnection("jdbc:mysql://localhost/db","root","abc");             statement st=con.createstatement();             //st.execute("create table student(rollno int,name varchar(20),class varchar(10))");             //st.execute("insert student values(1,'raj','fy')");             //st.execute("insert student values(2,'karan','sy')");             //st.execute("insert student values(3,'sameer','ty')");             //st.execute("delete student name='xyza'");             //st.executeupdate("update student set name='xyza',class='fy' rollno=3");             resultset rs=st.executequery("select*from student");             resultsetmetadata rsmd=rs.getmetadata();             string c1=rsmd.getcolumnname(1);             string c2=rsmd.getcolumnname(2);             string c3=rsmd.getcolumnname(3);             system.out.println(c1+"\t"+c2+"\t"+c3);             while(rs.next())             {                 int r=rs.getint("roll no");                 string n=rs.getstring("name");                 string c=rs.getstring(3);                 system.out.println(r+"\t"+n+"\t"+c);             }             con.close();             system.out.println("connection successfull");         }         catch(exception e)         {             system.out.println(e);         }     } } 

 int r=rs.getint("roll no");   

change line of code to

 int r=rs.getint("rollno"); 

because column named rollno, not roll no.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -