BufferedWriter error

the output of SQL query is around 19254 rows. But my below code writes only 18700 files. Sometimes the o/p file as 18900 rows. No idea why the file write is having error

publicclass Application_DBmap

{

String noofrecords="",dbcount="";

public Application_DBmap(){}

/*

This is for opening a database connection

*/

public Connection opendb()

{

Connection conn;

// Load the Oracle JDBC driver

try

{

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

conn = DriverManager.getConnection(

"jdbc:oracle:thin:@ip:port:MR","id","pwdl");

}

catch (SQLException ex)

{

returnnull;

}

return conn;

}

/*

This is for closing a database connection

*/

publicboolean closedb(Connection connobj)

{

try

{

connobj.close();

}

catch (SQLException ex)

{

returntrue;

}

returntrue;

}

/*

this is for finding a data in the index table for Report Class B

*/

public String CheckCountofRecords(Connection conn)

{

try

{

int data_flag=0;

String Noofrows="";

String sqlquery ="select count(*) from ALL_TABLES a, mlr.arsseg b , mlr.arsapp c where c.agid=b.agid and a.TABLE_NAME=b.TABLE_NAME";

Statement stmt = conn.createStatement();

System.out.println("2" );

ResultSet rset = stmt.executeQuery(sqlquery);

System.out.println("3" );

while (rset.next()){

Noofrows=rset.getString(1);

}

rset.close();

stmt.close();

return Noofrows;

}

catch (SQLException ex)

{

System.out.println("CheckCountofRecords" +ex);

return"false";

}

}

publicvoid Application_DBmap_update(Connection conn,BufferedWriter out)

{

try

{

int i=0;

String str,tablename="",Applicationame="",table_load_startdt="",table_load_stopdt="",table_load_closedt="";

String sqlquery ="select DISTINCT a.TABLE_NAME,c.NAME,b.start_date,b.stop_date,b.closed_date from ALL_TABLES a, mlr.arsseg b , mlr.arsapp c where c.agid=b.agid and a.TABLE_NAME=b.TABLE_NAME";

Statement stmt = conn.createStatement();

System.out.println("2" );

ResultSet rset = stmt.executeQuery(sqlquery);

System.out.println("3" );

while (rset.next()){

i=i+1;

System.out.println(i+":");

tablename=rset.getString("TABLE_NAME");

Applicationame=rset.getString("NAME");

table_load_startdt=rset.getString("start_date");

table_load_stopdt=rset.getString("stop_date");

table_load_closedt=rset.getString("closed_date");

out.write(i+":"+tablename+","+Applicationame+","+table_load_startdt+","+table_load_stopdt+","+table_load_closedt+"\n");

}

rset.close();

}

catch (IOException e)

{

System.out.println("i/o exception");

}

catch (SQLException ex)

{

System.out.println("CheckCountofRecords" +ex);

}

}

publicstaticvoid main(String arg[])

{

Application_DBmap obj=new Application_DBmap();

Connection conn;

String noofrecords="",dbcount="";

try

{

BufferedReader in =new BufferedReader(new FileReader("dbapplicationmap.txt"));

noofrecords=in.readLine();//read the number of tables from first line of i/p file

if ((conn = obj.opendb()) ==null)

{

System.out.println("open db error\n");

return;

}

dbcount=obj.CheckCountofRecords(conn);

if (noofrecords.equals(dbcount))

{

System.out.println("Count Equal\n");

}

else

{

System.out.println("Count Not Equal\n");

in.close();

BufferedWriter out =new BufferedWriter(new FileWriter("dbapplicationmap.txt"));

out.write(dbcount+"\n");

obj.Application_DBmap_update(conn,out);

}

System.out.println("file count ->"+noofrecords+""+"db count"+dbcount+"\n");

obj.closedb(conn);

in.close();

}

catch (IOException e)

{

System.out.println("i/o exception");

}

}//class main end

}// class Applcation_DBmap end

[8458 byte] By [anaik100a] at [2007-11-27 4:49:54]
# 1

Don't swallow exceptions. When you get an exception, always print it's stack trace!

catch (Exception e) {

e.printStackTrace();

}

Otherwise you may not even know that something went wrong, let alone what caused it.

hunter9000a at 2007-7-12 10:03:04 > top of Java-index,Java Essentials,Java Programming...
# 2
it is not throwing any exception
anaik100a at 2007-7-12 10:03:04 > top of Java-index,Java Essentials,Java Programming...
# 3
my problem is resolved. I had not closed the stream after writing to file. Hence i was getting the error
anaik100a at 2007-7-12 10:03:04 > top of Java-index,Java Essentials,Java Programming...