现在我的计数输出对于组合框中的每个元素都是0,即它类似于B10,B20,B30(B是默认值,下一项是数据库中的值,0表示此连接字符串中的计数)... ...我的计数没有增加
当我从Jcombobox中选择一个值时,我该怎么办才能增加计数 然后按下按钮,即我得到B10,B11,B12,B20,B21,B22,B30,B31,B32
public void actionPerformed(ActionEvent ae) {
String str = ae.getActionCommand();
if (str.equals("GENERATE PART NO. :")) {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/d03", "root", "");
st = con.createStatement();
String s = "select value from user1 where Userdata='" + jc.getSelectedItem() + "'";
rs = st.executeQuery(s);
t1.getText();
if (rs.next()) {
int j = 0;
String add1 = rs.getString("value");
t1.setEditable(false);
String str9 = new String();
str9 = "B" + add1; //B is the default value, add1 is the value from database
String str10 = new String();
str10 = str9 + j;
String query = "select MC from final";
ResultSet rs1 = st.executeQuery(query);
while (rs1.next()) {
if (str10.equals(rs1)) {
j = j + 1;
j=new Integer(j+1);
t1.setText(str10);
} else {
t1.setText(str10);
}
}
}
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/d03", "root", "");
String s1 = ("insert into final(MC)values(?)");
PreparedStatement pstm = con.prepareStatement(s1);
pstm.setString(1, t1.getText());
int rowi = pstm.executeUpdate();
if (rowi > 0) {
JOptionPane.showMessageDialog(null, "DATA INSERTED");
}
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "ERROR CLOSE");
}
}
答案 0 :(得分:0)
答案很简单:
将Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH
移至str10 = str9 + j;
正文。
您的(片段)代码应如下所示:
while