我尝试使用以下程序连接到数据库并从中提取数据。我可以稍后将其存储为 CSV。当我运行程序时,javaw.exe 进程在一段时间后自行终止。你能告诉我如何克服这个问题并且可以运行到最后吗?请在下面找到代码段
import java.io.BufferedOutputStream;
import java.sql.CallableStatement;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.sql.*;
import java.util.ArrayList;
public class myLogin{
public static void main(String args[]) {
String url = "";
String queryString;
String temp;
try {
Class.forName("com.sybase.jdbcx.SybDriver");
System.out.println("got it");
}
catch( Exception e ) {
System.out.println("Failed to load sybase driver.");
return;
}
try {
Connection con = DriverManager.getConnection(url, "", "");
Statement select = con.createStatement();
queryString=" ";
select.executeQuery(queryString);
ResultSet myResultSet = select.executeQuery(queryString);
System.out.println("Got results:");
String m="details.csv";
FileOutputStream fos=new FileOutputStream(m,false);
Writer out = new OutputStreamWriter(new BufferedOutputStream(fos));
while(myResultSet.next()) {
int ncols = myResultSet.getMetaData().getColumnCount();
for (int i=1; i<(ncols+1); i++) {
System.out.print(myResultSet.getMetaData().getColumnName (i));
if (i<ncols) System.out.print(","); else System.out.println();
}
do {
for (int i=1; i<(ncols+1); i++) {
out.append(myResultSet.getString(i));
System.out.print(myResultSet.getString(i));
if (i<ncols) System.out.print(","); else System.out.println();
}
} while (myResultSet.next());
}
select.close();
con.close();
}
catch( Exception e ) {
e.printStackTrace();
}
}
}