所以我有一个程序可以选择一个数据库并将其导出为 csv。当我导出数据库时,制表符分隔不保留任何数据类型。理想情况下,csv 应该将文本字段保留为“####”、“##”,而不仅仅是####、##。尽管这些字段是“数字”,但它们不需要被视为数字。这种缺乏格式会导致排序出现一个小问题,我可以看到 jackcess 支持数据类型,但我需要使用光标来保留这些数据类型,还是我仍然可以使用 exportFile() 函数?
public DBTool() {
JOptionPane.showMessageDialog(null, "Select an access database file to be converted to .csv");
String userhome = System.getProperty("user.home");
JFileChooser chooser = new JFileChooser(userhome);
//chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("Choose Database to Convert");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
source = chooser.getSelectedFile().toString();
destination = chooser.getCurrentDirectory() + "\\output.csv";
System.out.println("Source: " + source);
System.out.println("Destination: " + destination);
} else {
System.out.println("No Selection ");
}
}
public void openEDB(){
sourceF = new File(source);
long length = sourceF.length();
System.out.println(length);
try {
try {
db = new DatabaseBuilder(sourceF)
.setCodecProvider(new CryptCodecProvider("password"))
.open();
} catch (IOException ex) {
Logger.getLogger(DBTool.class.getName()).log(Level.SEVERE, null, ex);
}
db = DatabaseBuilder.open(sourceF);
} catch (IOException ex) {
Logger.getLogger(DBTool.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void exportDB(){
destinationF = new File(destination);
try {
ExportUtil.exportFile(db, "TableName", destinationF);
JOptionPane.showMessageDialog(null, "Success, .csv created: " + this.destination);
} catch (IOException ex) {
Logger.getLogger(DBTool.class.getName()).log(Level.SEVERE, null, ex);
}
}
}