Hello to all! I am doing practice for JDBC and using netbeans 8.1. I created a table in mc access and wrote a program. But the problem is that when i pass column index then my program runs successfully. But I pass column name as in my table in mc access then there occurs an error that "Column not found".
I am pasting code of my program and try to explain my problem further.
package database;
impot java.sql.*;

package database;
impot java.sql.*;

public class Database {

public static void main(String[] args) {


        String url = "jdbc:odbc:personDSN";    

        Connection con = DriverManager.getConnection(url);

        Statement st = con.createStatement();

        String sql = "SELECT *FROM students";

        ResultSet rs = st.executeQuery(sql);

            String Name = rs.getString(2);

           String add = rs.getString(3);

           String pNum = rs.getString(4);

           System.out.println(Name + " "  + add + " "  + pNum);


        catch(ClassNotFoundException | SQLException sqlEx)



As you can see in while loop that i have passed column index in getString() function. In this case my program runs successfully. But when i pass name of field/attribute which is in my database table, then it gives me error that "Column not found". For example if I pass getString("name") then it gives me above error.
Please help me to solve my problem.

Note: I have checked again and again that there is no spelling mistake in my parameter opposite to actual table in ms access.

2 Years
Discussion Span
Last Post by stultuske

Ehmmm silly question will
"SELECT *FROM students"

actually work?
Shouldn't it be with space?
"SELECT * FROM students"

I haven't touched DBs in ages :P

Edited by peter_budo


Peter: that might depend on the DB you use, but when you run a query like that in MS SQL Server Management Studia, it returns he data.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.