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");
}
答案 0 :(得分:0)
我需要插入&&在我的while循环中使用 model2.addRow(new Object [] {d1,d2,d3,d4}); dispose add column。
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://remote-mysq3003.servage.net:3306/alpha?zeroDateTimeBehavior=convertToNull", "username", "password");
Statement st = conn.createStatement();
Statement stx = conn.createStatement();
String query = "Select currency_code,Rate from currency";
String queryx = "Select Buying_Rate, Selling_Rate from Transaction";
ResultSet rs = st.executeQuery(query);
ResultSet rsx = stx.executeQuery(queryx);
while (rs.next()&& rsx.next()) {
String d1 = rs.getString("currency_code");
String d2 = rs.getString("Rate");
String d3 = rsx.getString("Selling_Rate");
String d4 = rsx.getString("Buying_Rate");
model2.addRow(new Object[]{d1, d2,d3,d4});
}
rsx.close();
rs.close();
stx.close();
st.close();
conn.close();
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "erro in Database");
}
谢谢你们