How to show data in java from database??

[b][red]This message was edited by siaoling at 2005-3-19 8:20:34[/red][/b][hr]
[b][red]This message was edited by siaoling at 2005-3-19 8:20:14[/red][/b][hr]
I am creating a database connection to my java.But now i have no ideas that why the data in my database is not shown.

I had put this code in a java class name Supermarket:
public class Supermarket {
public static void main(String[] args) {
SimpleReport supplier;
supplier = new SimpleReport();

And then i put another code which to link to Supermarket class which its name is SimpleReport:
public class SimpleReport {

private String sFileName;

// method for SimpleReport Class
public void setFileName(String sFileNameA) {
sFileName = sFileNameA;

public String getFileName() {
return sFileName;

// method to show report
public void showSimpleReport(){
Connection conDatabase;
Statement qryDatabase;
String sURL;

try {
/* load the jdbc-odbs beidge driver */
// set this to connection string to the database
//sURL = "jdbc:odbc:supermarket";
sURL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};";
sURL += "DBQ=" + getFileName() + ";";
sURL += "DriverID=22;READONLY=true}";

// create connection to database using connection string
conDatabase = DriverManager.getConnection(sURL, "", "");

// setup java.sql.Statement to run queries
qryDatabase = conDatabase.createStatement();

// specify SQL querty
qryDatabase.execute("select * from supplier");

// create result set from SQL query to connected database
ResultSet result = qryDatabase.getResultSet();

if (result !=null)
while ( {
System.out.println("row: " + result.getString(2) );
catch (Exception e) {
System.out.println("Error: " + e);

// 1st Constructor
public SimpleReport(){
sFileName = "i:\ISYS2048\supermarket.mdb";

// 2nd Constructor
public SimpleReport(String sFileNameA){
sFileName = sFileNameA;

From the coding and the logic,it shouldn't has any problem on it.But yet the data from database is not shown.So what should I do to show the data??

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!