views:

40

answers:

2

hi,

I am getting this error when I try to query the database and write results to a file. It never occured before.

java.sql.SQLException: Error writing file '/tmp/MYwADPLw' (Errcode: 28)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665) at com.mysql.jdbc.Connection.execSQL(Connection.java:3170) at com.mysql.jdbc.Connection.execSQL(Connection.java:3099) at com.mysql.jdbc.Statement.executeQuery(Statement.java:1169) at DBase.connect(DBase.java:58)
// this is where i call executequery at automateExport.main(automateExport.java:11) Exception in thread "main" java.lang.NullPointerException at automateExport.main(automateExport.java:13) // main class with db connection

The resultset I am expecting is very large. I never had this problem when I was querying for a smaller resultset. Could it be space issues? I have 117 gb on my disc. But I am expecting a max of 1gb text data. Any solutions???

My Code:

 public Connection connect(String db_connect_str,String db_userid, String db_password) {
        Connection conn;
        Statement stmt;
        String query;
     // inputfile - csv
        String input = "inputfile.txt";
        try {
         // to bifurcate heap memory error   
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(db_connect_str,db_userid, db_password);
            stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,  
                    java.sql.ResultSet.CONCUR_READ_ONLY);
            stmt.setFetchSize(Integer.MIN_VALUE); 

            query = "SELECT  r.name, r.network , r.namestring, i.name, i.description "+
            " , r.rid  , i.id, d.dtime ,d.ifInOctets , d.ifOutOctets , FROM_UNIXTIME(d.dtime)"+
            " FROM router AS r INNER JOIN interface AS i ON r.rid = i.rid " +
            "INNER JOIN  1278993600_1_60 AS d ON i.id = d.id " +
            "AND dtime BETWEEN " +startTime+ " AND "+ endTime +" WHERE r.network = 'ITPN'" +
                    "AND i.status = 'active' ORDER BY i.id, d.dtime";

            BufferedWriter fw = new BufferedWriter(new FileWriter(input));            
            ResultSet rs = stmt.executeQuery(query); 
            String idescp = null;
            // writing to file
            while (rs.next()) {
              if(rs.getString("description").equals(null)){
                  System.out.println("description" +rs.getString("description") );
                  idescp = "NA";
                  System.out.println("idescp :" +idescp + ":");
              }else{
                  idescp = rs.getString("description");
              }
              fw.write(rs.getString(1)+","+ rs.getString("rid")+","+ rs.getString("id") + "," +idescp+","
                      +rs.getString("dtime")+ "," +rs.getString("ifInOctets")+ "," + 
                      rs.getString("ifOutOctets") + ","+ rs.getString(11)+NL); 
            }

            fw.close();
            rs.close() ;
            stmt.close() ;
        } catch(Exception e) {
            e.printStackTrace();
            conn = null;
        }
        return conn;
    }

Please help. Thank you.

A: 

Maybe the database runs out of temp space on the file. I would check if ot the path given, the account the database is running on has the right and the space to write some data.

Frank
but i am running it and writing it on my machine. file gets created in my workspace
jillika iyer
And the MySQL engine is started with your account? Is there enough free space on the drive mentioned in the error message?
Frank
I have no idea which drive this could be: '/tmp/MYwADPLw' I am writing on my machine only. Just querying db for the data.
jillika iyer
could it be because of the complex query?? if i break the query down to 2 parts would that help???
jillika iyer
@jillika So the database is running on a server different from your machine? Who is administering that server? Maybe you should contact her/him and have them do the space check.
Frank
A: 

MySQL will write large resultsets to disk for streaming. The database server's /tmp folder is likely filling up as @Frank suggests.

Joshua Martell