我有以下程序,其中用戶必須提供訂單代碼才能獲取客戶端及其訂單的數據。我在我的數據庫Catalog
中看到了一個包含所有需要的數據的視圖。但是當我運行我的程序時,出現以下錯誤SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
。是因爲這個觀點嗎?或者我的代碼有問題?我也想知道rs.toString();
是否適合打印結果。爲什麼SQLException:[Microsoft] [ODBC SQL Server驅動程序] Invalid Descriptor Index and toString
public class Orders {
public static void main(String[] args) {
int order_code;
int cust_code;
int quantity;
double price;
String name;
Scanner input = new Scanner (System.in);
System.out.print("Please insert order code: ");
order_codej = input.nextInt();
String url = "jdbc:odbc:orders";
Connection dbcon;
Statement stmt;
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e) {
System.out.print("ClassNotFoundException: ");
System.out.println(e.getMessage());
}
try {
dbcon = DriverManager.getConnection(url,"mybase", "mycode");
stmt = dbcon.createStatement();
rs = stmt.executeQuery("SELECT * FROM Catalog WHERE o_code="+order_code);
while (rs.next()) {
order_code = rs.getInt("o_code");
cust_code = rs.getInt("cust_code");
quantity = rs.getInt("quantity");
price = rs.getFloat("price");
name = rs.getString("name");
}
rs.toString();
rs.close();
stmt.close();
dbcon.close();
}
catch(SQLException e:) {
System.out.print("SQLException: ");
System.out.println(e.getMessage());
}
}
}
在此先感謝!
CREATE VIEW目錄AS SELECT Orders.o_code,Orders.cust_code,名稱,價格,Consists.quantity 從接單,客戶,產品,下設 WHERE Orders.cust_code = Customers.cust_code AND Orders.o_code =組成。 o_code AND Consists.product_code = Product.product_code – MariaP