Reputation: 208
I am using opencsv library to dump oracle data into csv file.
I am using below code:
private void generateCSVFile() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:XE";
Connection con = DriverManager.getConnection(url, "system", "admin");
PreparedStatement ps = con.prepareStatement("select * from T_USER_DETAILS",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE,ResultSet.HOLD_CURSORS_OVER_COMMIT);
ResultSet rs = ps.executeQuery();
if(rs.next()){
System.out.println("Name = "+rs.getString(2));
}
rs.beforeFirst();
CSVWriter writer = new CSVWriter(new FileWriter("Test.csv"),'\t');
writer.writeAll(rs, true);
JOptionPane.showMessageDialog(null, "CSV Created!","Success!",JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
Logger.getLogger(BackupDB.class.getName()).log(Level.SEVERE, null, ex);
}
}
but, when i executing this code. csv file is created but there is no content in that file. (note result set prints the 2 column value in console).
Thanks in Advance.
Upvotes: 1
Views: 3426
Reputation: 549
Couple of things you may try:
List<String[]test>
in the constructor to give it a try. if it works that means your result set has problems.Upvotes: 3