使用java导出sqlite数据库
我想将sqlite db导出/另存为另一个空间,例如:C、D、anywhere 通过使用java。。。 我希望有人能帮我解决这个问题。。 观点是 也许使用JavaSwing制作一个接口,这个程序有一个sqlite数据库,我们有一个按钮保存为按下,可以将这个数据库保存到另一个空间 我找不到很多资源可以查找,所以我希望有人能帮助我完成这个程序。 我将非常高兴并感谢您。SQLite允许您附加另一个数据库文件,该文件可以位于任何位置。然后,您只需使用SQL语句即可。这是你想要的东西 将数据库“/the/path/to/the/other/db.sqlite”作为otherdb附加; 创建表otherdb.theTableName。。。; 插入到otherdb.theTableName中,从main.theTableName中选择*; 或者,在没有打开连接的情况下,只需复制DB文件使用java导出sqlite数据库,java,sqlite,Java,Sqlite,我想将sqlite db导出/另存为另一个空间,例如:C、D、anywhere 通过使用java。。。 我希望有人能帮我解决这个问题。。 观点是 也许使用JavaSwing制作一个接口,这个程序有一个sqlite数据库,我们有一个按钮保存为按下,可以将这个数据库保存到另一个空间 我找不到很多资源可以查找,所以我希望有人能帮助我完成这个程序。 我将非常高兴并感谢您。SQLite允许您附加另一个数据库文件,该文件可以位于任何位置。然后,您只需使用SQL语句即可。这是你想要的东西 将数据库“/the/
try{
filename = null;
HSSFWorkbook hwb=new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("Invoice No");
rowhead.createCell((short) 1).setCellValue("Date");
rowhead.createCell((short) 2).setCellValue("Customer");
rowhead.createCell((short) 3).setCellValue("Reference No.");
rowhead.createCell((short) 4).setCellValue("Qty");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/animal1", "root", "315921");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from few1");
int i=1;
while(rs.next()){
HSSFRow row= sheet.createRow((short)i);
row.createCell((short) 0).setCellValue(rs.getString("Invoice"));
row.createCell((short) 1).setCellValue(rs.getString("Date"));
row.createCell((short) 2).setCellValue(rs.getString("Customer"));
row.createCell((short) 3).setCellValue(rs.getString("Reference"));
row.createCell((short) 4).setCellValue(rs.getString("Qty"));
i++;
}
JFileChooser fileChooser = new JFileChooser();
int retval = fileChooser.showSaveDialog(null);
if (retval == JFileChooser.APPROVE_OPTION) {
filename = fileChooser.getSelectedFile();
if (!filename.getName().toLowerCase().endsWith(".xls")) {
filename = new File(filename.getParentFile(), filename.getName() + ".xls");
}
}
FileOutputStream fileOut = new FileOutputStream(filename);
hwb.write(fileOut);
fileOut.close();
JOptionPane.showMessageDialog(this, "Your excel file has been generated!");
} catch ( IOException | ClassNotFoundException | SQLException ex ) {
System.out.println(ex);
}
它用于Java导出Microsoft excel中的MySQL数据。这里不是自由职业者。它叫Stackoverflow。请您尝试重新格式化代码,使其正确对齐和格式化。