1

I have made the connection with MS-access database in Java , my data base consists of 400,000 records. I have seen only 5629 records in the java console. I need to display all the data in the console for the column 3 in the data base and i don't know what is the reason for getting only 5629 records ??? my code is :-

 import java.sql.*;
public class DataBaseConnection {

public static void main(String[] args) {
            try {

                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                Connection con = DriverManager.getConnection("jdbc:odbc:DEVELOPER");
                System.out.print("connection is successful");
                Statement stat=con.createStatement();
                ResultSet res=stat.executeQuery("SELECT * FROM data");
                int index=0; 
                while (res.next())
                {
                System.out.println(res.getString(3));
                }
             }
           catch (Exception e)
             {

             e.printStackTrace();
             }

    }
 }
carexcer
  • 1,407
  • 2
  • 15
  • 27
mumenh
  • 17
  • 1
  • 8
  • run a count(*) query first and show us the result – isah Jan 17 '14 at 13:10
  • I'm sure you're getting all your results in the set, but the console only allows a certain number of lines. Why on earth would you want 400,000 pieces of data displayed on your console? Were you going to look through them _one by one_? – Paul Samsotha Jan 17 '14 at 13:13
  • Are you getting any error? Could you try `SELECT count(*) FROM Data` and post the result? As a last resort: have you tried the [ucanaccess](http://ucanaccess.sourceforge.net/site.html) driver instead of the JDBC-ODBC bridge?And of course make absolutely certain you are not falling in the case described by peeskillet!!! – Nikos Paraskevopoulos Jan 17 '14 at 13:14
  • when i run the SELECT count(*) FROM data i got the results 400000 but i doesn't display all in the console, it just display the last part of 400000 not from begining – mumenh Jan 17 '14 at 13:18
  • As pointed out by @MarkoTopolnik in a comment from [this question](http://stackoverflow.com/q/20799763/2587435) - _"And you wouldn't by any chance rely on Eclipse/NetBeans Console window to count the lines? If yes, then there's your problem: the window has a maximum scrollback limit set to 1500 lines. "_ – Paul Samsotha Jan 17 '14 at 13:21

1 Answers1

0

I bet you have a NULL value in your database. Check the field for null before printing it out:

while (res.next())
{
   String output = res.getString(3);
   if ( res.wasNull() )
      System.out.println( "NULL" );
   else
      System.out.println(output);
}
Kieveli
  • 10,944
  • 6
  • 56
  • 81