给你个例子:
package sql;import java.io.File;
import java.io.FileOutputStream;
import java.sql.*;
class Access{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
Access(String s) throws Exception{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:People","","");
stmt=conn.createStatement();
rs=stmt.executeQuery( "SELECT * FROM table1 ");
byte[] b = null;
FileOutputStream fout = new FileOutputStream(new File("d:ax.txt"));
ResultSetMetaData meta = rs.getMetaData();
for(int i=1; i<meta.getColumnCount();i++){
b = (meta.getColumnName(i) + "\t").getBytes();
fout.write(b);
}
while(rs.next()){
fout.write("\r\n".getBytes());
for(int i=1; i<meta.getColumnCount();i++){
b = (rs.getString(i) + "\t").getBytes();
fout.write(b);
}
}
fout.close();
//没有就把此用?名加入到userid表
//?句有毛病 ??提示?下面
conn.close();
}catch(ClassNotFoundException e){
}catch(SQLException e1){}
}
public static void main(String args[]) throws Exception{
new Access("2");
// System.in.read(byte[] b, int off, int len);
}
}
package sql;import java.io.File;
import java.io.FileOutputStream;
import java.sql.*;
class Access{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
Access(String s) throws Exception{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:People","","");
stmt=conn.createStatement();
rs=stmt.executeQuery( "SELECT * FROM table1 ");
byte[] b = null;
FileOutputStream fout = new FileOutputStream(new File("d:ax.txt"));
ResultSetMetaData meta = rs.getMetaData();
for(int i=1; i<meta.getColumnCount();i++){
b = (meta.getColumnName(i) + "\t").getBytes();
fout.write(b);
}
while(rs.next()){
fout.write("\r\n".getBytes());
for(int i=1; i<meta.getColumnCount();i++){
b = (rs.getString(i) + "\t").getBytes();
fout.write(b);
}
}
fout.close();
//没有就把此用?名加入到userid表
//?句有毛病 ??提示?下面
conn.close();
}catch(ClassNotFoundException e){
}catch(SQLException e1){}
}
public static void main(String args[]) throws Exception{
new Access("2");
// System.in.read(byte[] b, int off, int len);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货