67,512
社区成员
发帖
与我相关
我的任务
分享
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 + "已创建!");
}
}
}
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();
}
}
}
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();
}
}