使用Mysql和Java在一列中插入多个选择值(insert multiple select value in one column using Mysql and Java)

编程入门 行业动态 更新时间:2024-10-09 00:42:26
使用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?

更多推荐

本文发布于:2023-08-07 12:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464150.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   Java   Mysql   insert   column

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!