大神们帮小弟看看 重新发贴

无码男 2014-06-23 08:49:02
做个导出功能
当点击导出
1.在服务器端创建个文件.excle
2,.将数据库出来的数据集
3.客户端 将此文件下载 并删除服务器端的文件
以下是创建文件

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;

public class CreatFile {

public static BufferedReader bufread;

//指定文件路径和名称
private static String path = "G:\\ls\\" + 2+ ".xls";
private static File filename = new File(path);
private static String readStr ="";


/** *//**
* 创建文本文件.
* @throws IOException
*
*/
public static void creatTxtFile() throws IOException{
if (!filename.exists()) {
filename.createNewFile();
System.err.println(filename + "已创建!");
}
}

}
...全文
134 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
无码男 2014-06-24
  • 打赏
  • 举报
回复
能帮我测测试测试吗
yanghongjy 2014-06-24
  • 打赏
  • 举报
回复
什么问题? 功能不能用? 还是有异常?
无码男 2014-06-23
  • 打赏
  • 举报
回复
走过路过的大哥大姐帮帮小弟呗
无码男 2014-06-23
  • 打赏
  • 举报
回复
以下是将结果集存到服务器

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.ResultSetMetaData;
import java.sql.SQLException; 

public class UP{ 
    



	public static void main(String[] args) throws IOException { 
        String driver = " "; 
        String dbName = " "; 
        String passwrod = " "; 
        String userName = " "; 
        String url = "" + dbName; 
        String sql = "select * from "; 
        CreatFile.creatTxtFile();
  
        try { 
            Class.forName(driver); 
            Connection conn = DriverManager.getConnection(url, userName,passwrod); 
            PreparedStatement ps = conn.prepareStatement(sql); 
            ResultSet rs = ps.executeQuery(); 
            ResultSetMetaData rt = rs.getMetaData() ; 
            int columnCount = rt.getColumnCount();//获取列数
//            int rh=rs.getRow();

            PrintWriter pr=new PrintWriter(("path"));   
          
           for(int i=0;i<columnCount;i++){    //打印
//        	   for(int h=0;h<rh;h++){
            	pr.print(rs.getString(i));
//        	   }
            }
           
            		pr.close();//关闭流
            
  
            // 关闭记录集 ;
            if (rs != null) { 
                try { 
                    rs.close(); 
                } catch (SQLException e) { 
                    e.printStackTrace(); 
                } 
            } 
  
            // 关闭声明 
            if (ps != null) { 
                try { 
                    ps.close(); 
                } catch (SQLException e) { 
                    e.printStackTrace(); 
                } 
            } 
  
            // 关闭链接对象 
            if (conn != null) { 
                try { 
                    conn.close(); 
                } catch (SQLException e) { 
                    e.printStackTrace(); 
                } 
            } 
  
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    } 
  
} 
无码男 2014-06-23
  • 打赏
  • 举报
回复
以下是客户端下载

import java.io.File;
import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.io.IOException;


public class Download {
	//传入文件路径下载
    protected void DownLoad(String filePath) throws IOException{
    	
    	FileInputStream fis=new FileInputStream(new File(filePath));
    	FileOutputStream fos = new FileOutputStream(new File(filePath));
    	byte[] b=new byte[1];
    	while(fis.read(b)!=-1){
    		fos.write(b);
    		fos.flush();
    	}
    	fis.close();
    	fos.close();
    	
    }
}

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧