本文介绍了它给我一个错误,说找不到列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这给我一个错误,提示未找到列

Its giving me an 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 into student values(1,'Raj','Fy')");
            //st.execute("insert into student values(2,'Karan','Sy')");
            //st.execute("insert into student values(3,'sameer','Ty')");
            //st.execute("delete from student where name='xyza'");
            //st.executeUpdate("update student set name='xyza',class='Fy' where 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");

将此代码行更改为

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

因为您的列名为rollno,而不是roll no.

Because your column is named rollno, not roll no.

这篇关于它给我一个错误,说找不到列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 09:56