我想从DATAENTRY类的文本字段中获取值到我当前的类SoilTable中,以使表格正常工作
private void btgetinvActionPerformed(java.awt.event.ActionEvent evt) {
try { //my class DATAENTRY from which i have to fetch the value of textfield tf_rm_id
DBUtil util = new DBUtil();
Connection con = util.getConnection();
PreparedStatement stmt = con.prepareStatement("select COUNT(box_no)as total from mut_det WHERE rm_id = ?");
ResultSet rs;
String rm = tf_rm_id.getText().trim();
stmt.setInt(1, Integer.parseInt(rm));
rs = stmt.executeQuery();
while (rs.next()) {
tf_boxno.setText(rs.getString("total"));
}
这是我的班级,我想替换textfield tf_rm_id的值为?参数
try { // My current class SoilTable
DBUtil util = new DBUtil();
Connection con = util.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from soil_det where rm_id=?");
String rmn = (tf_rm_id.getText() == null || tf_rm_id.getText().equals("")) ? "0" : tf_rm_id.getText();
stmt.setLong(1, Long.parseLong(rmn));
答案 0 :(得分:1)
如果我理解得很好(你的代码不是很清楚),我会创建一个方法并返回该值。
在你的另一个类中,我会创建该类的一个对象并调用该方法,然后根据需要将其分配给另一个值,如:
// DATAENTRY class
public String getVal()
{
return tf_rm_id;
}
// SoilTable
DATAENTRY textFieldVal = new DATAENTRY();
String strTextFieldVal = textFieldVal.getVal();
//assigned a new value
strTextFieldVal = " field value manipulated";
//or display it directly:
System.out.println("Value recieved: "+textFieldVal.getVal());