Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

example of jdbc

 
mansoor iqbal
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need an example of a simple class which shows me how to make a jdbc connection to an ms access database and use of a select query ....
i will be grateful...
thanks in advance
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a bunch of pages out there that will help, but basically the steps are

  1. Create you MS Access file
  2. Register your file with ODBC
  3. Start making calls to it!

  4. Dave.
 
kim jungil
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mansoor iqbal:
i need an example of a simple class which shows me how to make a jdbc connection to an ms access database and use of a select query ....
i will be grateful...
thanks in advance

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection mycon = DriverManager.getConnection("jdbc dbc:dsn_name","user_name","password");
PreparedStatement pstmt = mycon.prepareStatement
("select * from tablename",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = pstmt.executeQuery();
} catch(Exception e) {
System.out.println(e);
}
 
kim jungil
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[This message has been edited by kim jungil (edited October 15, 2001).]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.sql.*;
public class DBAccess{
public static void main(String[] args)
{
// Load the driver
try
{
// Load the driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Define the data source for the driver
String yourURL = "jdbc dbc:yourDSName";
// Create a connection through the DriverManager
Connection dConnection =
DriverManager.getConnection(yourURL);
Statement stmt = dConnection.createStatement();
ResultSet RS = stmt.executeQuery(
"SELECT some columns from your DB"
// Output the resultset data
while(RS.next())
System.out.println("your selected columns));
}
catch(ClassNotFoundException c)
{
System.err.println(c);
}
catch(SQLException s)
{
System.err.println(s);
}
}
}
------------------
Bosun
 
mansoor iqbal
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ty ty ty ty all!!!
but
i tried the code and it works fine. the only problem is that i am using swing to display the results......and as soon as i scroll the table by pressing the down-arrow key , i get the dreaded "illegal operation ..."...
i have run the the program 10 times and it does the same thing every time...
HELP!
 
kim jungil
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mansoor iqbal:
ty ty ty ty all!!!
but
i tried the code and it works fine. the only problem is that i am using swing to display the results......and as soon as i scroll the table by pressing the down-arrow key , i get the dreaded "illegal operation ..."...
i have run the the program 10 times and it does the same thing every time...
HELP!

if it is possible, you can paste your code here or we do not know the problem exactly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic