使用Mysql和Java在一列中插入多个选择值(insert multiple select value in one column using Mysql and Java)
嗨这是我的第一篇文章...希望能找到答案>。<
alert( alertNo , sqlstat , dbName , username , password , ipAddr , recipient , comments )
<select multiple name="recipient"> <option value="select">select</option> while (rs.next()) { String recipient = rs.getString("hp") + " " + rs.getString("lastname"); %> <option value=<%=recipient%>><%=recipient%></option> <% } } catch (SQLException sqe) { out.println("home" + sqe); } %> </select>我希望得到类似的东西
|收件人|
| 12345678,87654321 |
Hi this is my first post...Hope to find answer this >.<
alert(alertNo, sqlstat, dbName, username, password, ipAddr, recipient, comments)
<select multiple name="recipient"> <option value="select">select</option> while (rs.next()) { String recipient = rs.getString("hp") + " " + rs.getString("lastname"); %> <option value=<%=recipient%>><%=recipient%></option> <% } } catch (SQLException sqe) { out.println("home" + sqe); } %> </select>I hope to get something like
|Recipient |
|12345678,87654321 |
最满意答案
Yoy也许可以尝试为收件人创建一个pojo,如下所示:
private String sqlstat; private String dbName; private String username; private String password;当然,对于他们各自的getter和setter,这个pojo将是另一个java类,例如:Recipient.java。 然后回到你的主类,你可以从收件人创建一个List对象,就像这样
private List<Recipient> lstRecipient = new ArrayList<Recipient>(); while (rs.next()){ Recipient tempRecipient = new Recipient(); tempRecipient.setsqlstat(rs.getString("hp")); tempRecipient.setdbName(rs.getString("dbName")); tempRecipient.setusername(rs.getString("username")); tempRecipient.setpassword(rs.getString("password")); //after you've saved the first row of data of rs on tempRecipient //you add the data of tempRecipient on the list lstRecipient.add(tempRecipient); }如果你想显示你在lstRecipient中保存的所有数据,你可以简单地创建一个for语句来刷新数据
for ( Recipient tempRecipient : lstRecipient){ System.out.println("sqlstat: " + tempRecipient.getsqlstat() ); System.out.println("dbName: " + tempRecipient.getdbName() ); System.out.println("username: " + tempRecipient.getusername() ); System.out.println("password: " + tempRecipient.getpassword() ); //or if you want to send those values to an String String sql = "INSERT INTO alert(sqlstat, dbName, username, password)" + "VALUES('"+tempRecipient.getsqlstat()+"' ,'"+tempRecipient.getdbName() + "','"+tempRecipient.getusername() +"', '"+tempRecipient.getpassword() +"')"; // then execute the sql }我希望能提供一些帮助。
For those who want to do the same thing as me, do research more on String tokenizer in sql. Does PL/SQL have an equivalent StringTokenizer to Java's?
更多推荐
发布评论