Quering and writing to a file : errorcode 28
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开发者_Python百科 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.
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.
MySQL will write large resultsets to disk for streaming. The database server's /tmp folder is likely filling up as @Frank suggests.
精彩评论