好了,所以這是我的代碼無法轉換爲內部表示JDBC
public static ArrayList getMaterialerFraOrdreNr(String s_date, String e_date) throws SQLException, InterruptedException {
int tal = 0;
ArrayList nameOfColumns = getNameOfColumns(); // name of columns
ArrayList orderNumber = getOrdre_Nr_FromDB(s_date, e_date); // order number
//første loop kører gennem number of columns
//anden loop kører gennem name of column
ResultSet rs = null;
Connection con = null;
try {
Class.forName(DB.driver);
con = DriverManager.getConnection(DB.URL, DB.ID, DB.PW);
for (int i = 1; i < orderNumber.size(); i++) {
for (int j = 1; j < nameOfColumns.size(); j++) {
String nameOfColum = (String) nameOfColumns.get(i);
int orderNr = (Integer) orderNumber.get(j);
System.out.println("orderNr " + orderNr);
//SELECT v1001 FROM ORDRE_spec WHERE ordre_nr = 1;
String query = "SELECT ? AS ans FROM ordre_spec WHERE ordre_nr = ?";
PreparedStatement prest = con.prepareStatement(query);
prest.setString(1, nameOfColum);
prest.setInt(2, orderNr);
System.out.println("orderNr " + orderNr);
System.out.println("nameOfColum = " + nameOfColum);
rs = prest.executeQuery();
if(rs.next()){
tal = rs.getInt("ans");
MaterialeNum.add(tal);
System.out.println("materiale num = " + MaterialeNum);
}
}
}
} catch (ClassNotFoundException | SQLException ee) {
System.out.println("fail og der er så her");
System.err.println(ee);
} finally {
con.close();
}
System.out.println(kundeNum.toString());
return kundeNum;
}
public static void main(String[] args) throws SQLException, InterruptedException {
NewClass.getMaterialerFraOrdreNr("1990-10-10", "2020-10-10");
}
而我的問題是,我得到一個值java.sql.SQLException:無法轉換爲內部表示
我真的不能看到什麼錯誤應該是.. plz幫助,如果你可以看到錯誤:)
請在您的catch塊中添加printStackTrace語句。重新運行你的程序,並告訴我們這個例外。異常可能會指示異常發生在哪一行 – Arunkumar
當數據庫中的類型與您的rs.getXXX()rs.setXXX()類型不兼容時,通常會拋出該異常。告訴我們你餐桌的架構。 – leonbloy
這是StackTrace java.sql.SQLException:無法轉換爲內部表示 java.lang.Throwable:打印堆棧跟蹤: \t at com.sun.corba.se.impl.util.Utility.printStackTrace(Utility.java :933) \t at data.NewClass.getMaterialerFraOrdreNr(NewClass.java:192) \t at data.NewClass.main(NewClass.java:204) – HOervald