Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cannot get the result from db

Status
Not open for further replies.

sohjai

Programmer
Nov 23, 2001
8
HK
I wrote this code to connect a MS Access database.

import java.sql.*;

public class Temp {
public static void main(String args[]) {
Connection con;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection
("jdbc:eek:dbc:test;PWD=abc");
Statement stmt = con.createStatement();
String sql = "select uid from testing";
ResultSet rs = stmt.executeQuery(sql);
System.out.println(rs.getRow());
} catch(ClassNotFoundException e){
System.out.println(e.toString());
} catch(SQLException e){
System.out.println(e.toString());
}
}
}


However, the result of System.out.println(rs.getRow()); is 0, then I opened the file using Microsoft access and I found that the 10 records I entered before is still there, so can anyone help me what is going wrong and how can I retrieve the record from my code??
 
Try using this:

import java.sql.*;

public class Temp {
public static void main(String args[]) {
Connection con;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection
("jdbc:eek:dbc:test;PWD=abc");
Statement stmt = con.createStatement();
String sql = "select uid from testing";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
{
System.out.println ("The First Column is :" + rs.getInt (1));
}
} catch(ClassNotFoundException e){
System.out.println(e.toString());
} catch(SQLException e){
System.out.println(e.toString());
}
}
}
Thanks and regards,
Pazhanikanthan. P
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top