Results 1 to 8 of 8
Thread: Java Database handling problem
- 12-03-2012, 11:41 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
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.Last edited by Sanjaya; 12-03-2012 at 11:48 AM.
- 12-03-2012, 02:06 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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?Please do not ask for code as refusal often offends.
- 12-03-2012, 03:10 PM #3
Re: Java Database handling problem
Moved from New to Java
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-04-2012, 04:40 AM #4
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Re: Java Database handling problem
'Invalid cursor position' error is given when running with DISTINCT keyword
- 12-04-2012, 04:49 AM #5
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
- 12-04-2012, 09:25 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.Please do not ask for code as refusal often offends.
- 12-06-2012, 05:47 AM #7
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Re: Java Database handling problem
Database is Ms Access 2007
- 12-06-2012, 09:35 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
java file handling problem
By decode_urself in forum New To JavaReplies: 5Last Post: 04-05-2012, 02:35 PM -
java insert data into database problem
By chyeeqi in forum NetBeansReplies: 3Last Post: 03-29-2010, 01:36 AM -
Java database/method display problem
By thelinuxguy in forum Advanced JavaReplies: 3Last Post: 02-20-2009, 07:56 PM -
Problem in File Handling in Java
By getbiplab in forum New To JavaReplies: 6Last Post: 03-31-2008, 12:02 PM -
Problem connecting to my Database using Java
By javaneed in forum New To JavaReplies: 3Last Post: 08-13-2007, 09:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks