일부 사용자가이 오류를보고 왜이 오류가 발생하는지 알려 줄 수 있습니까? MySQL 데이터베이스에서 테이블을 가져 와서 텍스트 파일로 인쇄하려고합니다. 나는 위에 나열된 오류를 제공합니다.형식 불일치 : 개체 유형 문자열에서 개체 문자열로 변환 할 수 없습니다.
package db;
import java.io.*;
import java.sql.*;
import java.util.*;
public class TableToTextFile {
public static void main(String[] args) {
List<int[]> data = new ArrayList();
try {
Connection con = null;
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select * from employee");
while (rs.next()) {
String id = rs.getString("emp_id");
String name = rs.getString("emp_name");
String address = rs.getString("emp_address");
String contactNo = rs.getString("contactNo");
data.add(id + " " + name + " " + address + " " + contactNo);
}
writeToFile(data, "Employee.txt");
rs.close();
st.close();
} catch (Exception e) {
System.out.println(e);
}
}
private static void writeToFile(java.util.List list, String path) {
BufferedWriter out = null;
try {
File file = new File(path);
out = new BufferedWriter(new FileWriter(file, true));
for (String s : list) {
out.write(s);
out.newLine();
}
out.close();
} catch (IOException e) {
}
}
}
어디에서 오류가 발생합니까? 테이블의 데이터 유형은 무엇입니까? – MadProgrammer
주어진 답을 사용해도 문제가 해결되지 않으면 오류가 발생한 곳을 알려주십시오. 감사! –