Results 1 to 5 of 5

Thread: MS Access Database problem - No data found [Resolved]

Threaded View

  1. #1

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    Resolved MS Access Database problem - No data found [Resolved]

    Hi guys,

    Bit of a puzzler here. I've written an app that connects to a MSAccess DB fine. The DB has 3 colums - Employeename (Text or String), PassId (Number/long) and Passdate (Date/Time). All 3 columns have data entered in them. I can retrieve info from the first column but whenever I try to get data from the other two, tthe SQL Exception thrown tells me No Data Found.

    Would really appreciate any help you could give me. Thanks in advance.

    Code:
    import java.sql.*;
    import java.util.Date;
    import java.util.Calendar;
    
    public class Interactor {
    	
    	
    private String URL = ""; private String username = ""; private String password = ""; private int employees = 0; private Statement stmt = null; private Connection con = null; private String dataSourceName = "NewTest"; public Interactor ( String u, String p ) { dataSourceName = "NewTest"; URL = "jdbc:odbc:" + dataSourceName; username = u; password = p; setupConnection (); } private void P ( String S ) { System.out.print ( S ); } private void PL ( String S ) { System.out.println ( S ); } public void setupConnection () { try { Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver" ); } catch ( Exception e ) { System.out.println ( "Failed to load JDBC/ODBC driver." ); return; } try { con = DriverManager.getConnection ( URL, "", "" ); stmt = con.createStatement (); } catch ( Exception e ) { System.err.println ( "problems connecting to " + URL ); System.err.println ( e.getMessage () ); e.printStackTrace (); } } public void getPassDates () { try { ResultSet result = stmt.executeQuery ( "SELECT * FROM Emp;" ); result.next(); PL ( result.getString ( "Employeename" ) ); PL ( "" + result.getLong ( "PassId" ) ); PL ( result.getDate ( "Passdate" ).toString () ); while ( result.next () ) { count ++; PL ( result.getDate ( "Passdate" ).toString () ); PL ( "" + result.getLong ( "PassId" ) ); } } catch ( Exception e ) { System.err.println ( e.getMessage () ); e.printStackTrace (); } } public int getNoEmployees () { try { String q = "SELECT Employeename FROM Emp;"; ResultSet result = stmt.executeQuery ( q ); result.next(); // move to first row PL ( result.getString ( "Employeename" ) ); //PL ( result.getDate ( 1 ).toString () ); employees = 1; while ( result.next () ) { employees ++; PL ( result.getString( "Employeename" ) ); //PL ( result.getDate ( "Passdate" ).toString () ); } PL ( "Number of employees : " + employees ); } catch ( Exception e ) { System.err.println ( e.getMessage () ); e.printStackTrace (); } return employees; }
    }

    <Moderator added green checkmark to the thread>
    Last edited by NoteMe; Feb 22nd, 2005 at 12:52 PM.
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width