[英]How do I get the corresponding constant variable name for the integer value of -101 an Oracle SQL type from ResultSet.getMetaData().getColumnType(i)
[英]How do i get variable name of jbutton here“s101”?
我想獲取jbutton的值並將其與數據庫列進行比較,並設置標簽的文本
private void s101ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/abc","root","");
PreparedStatement stm = con.prepareStatement("select * from seats where Seat_id="+s101.getName());
ResultSet rs = stm.executeQuery();
while(rs.next())
// if(s101.getAccessibleContext().equals(rs.getString("Seat_id")))
{
lbl_id.setText(rs.getString("Seat_id"));
lbl_name.setText(rs.getString("Seat_name"));
lbl_price.setText(rs.getString("Price"));
lbl_type.setText(rs.getString("Type"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
我想您想在按鈕上顯示文本並將其與數據庫值進行比較。 為了實現這一點,您應該從動作事件中獲取源代碼。
JButton button = (JButton) evt.getSource();
String name = button.getText();
然后使用名稱與數據庫進行比較。
name.equals(rs.getString("Seat_id")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.