抱歉,我是 Java 新手,我正在尝试从我的数据库中包含 set_ID 、Buying_Rate 和Selling_Rate的Transaction表中获取值。我只想从 Transaction 表中显示Buying_rate 和Selling_rate 。我想将 Transaction 表中的数据显示到 Sell Rate列 和Buy Rate 列。这是我的尝试
DefaultTableModel model2 = (DefaultTableModel) provider.p1.getModel();
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://remote-mysq3003.servage.net:3306/alpha?zeroDateTimeBehavior=convertToNull", "username", "password");
Statement st = conn.createStatement();
Statement st_cus = conn.createStatement();
String query = "Select *from currency";
ResultSet rs = st.executeQuery(query);
String fx_rates = "Select Buying_Rate, Selling_Rate from Transaction";
ResultSet rsx = st.executeQuery(fx_rates);
while (rs.next()) {
String d1 = rs.getString("currency_code");
String d2 = rs.getString("Rate");
String d3 = rsx.getString("Buying_Rate");
String d4 = rsx.getString("Selling_Rate ");
model2.addRow(new Object[]{d1, d2});
model2.addColumn(new Object[]{d3, d4});
}
rs.close();
rsx.close();
st.close();
st_cus.close();
conn.close();
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "erro in Database");
}