Java Database handling problem
Connection con;
Statement stmt;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "Database";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection con = DriverManager.getConnection(dbURL, "","");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIV E,
ResultSet.CONCUR_READ_ONLY);
String sql="SELECT DISTINCT DaysGiven FROM IssueBooks";
rs=stmt.executeQuery(sql);
DefaultListModel listModel = new DefaultListModel();
while(rs.next()){
listModel.addElement(rs.getString("DaysGiven"));
}
list1.setModel(listModel);
stmt.close();
}
catch(Exception err){
System.out.println(err.getMessage());
}
}
Please tell me what the wrong with this code is. When I change the sql command like this "SELECT DaysGiven FROM IssueBooks" it works. But I want to use DISTINCT keyword to remove duplicates. Please tell me how to do that.
Re: Java Database handling problem
Please use [code] tags [/code] when posting code.
Unformatted code is hard to read.
What exception or error do you get when running the code with the DISTINCT keyword?
Re: Java Database handling problem
Moved from New to Java
db
Re: Java Database handling problem
'Invalid cursor position' error is given when running with DISTINCT keyword
Re: Java Database handling problem
Which database are you using?
Re: Java Database handling problem
Don't use SCROLL_SENSITIVE.
Why people insist on using scrollable result sets I do not know.
They're costly, especially the sensitive ones.
You do not need it.
Just use the createStatement() with no parameters.
I don't know if that is the problem, but I'm guessing you're on something like Access.
Re: Java Database handling problem
Database is Ms Access 2007
Re: Java Database handling problem
And what happens if you remove all the SCROLL stuff from your createStatement() call, like i suggested?