1

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 save multiple value into the same column(recipient). This is my insert statement.

String sql = "INSERT INTO alert(sqlstat, dbName, username, password, ipAddr,recipient, comments)"+ "VALUES(?,?,?,?,?,?,?)";

|Recipient |


|12345678 |

this is my current result.

I hope to get something like

|Recipient |


|12345678,87654321 |

2 Answers2

0

Yoy maybe can try creating a pojo for recipient, like this:

    private String sqlstat;
    private String dbName;
    private String username;
    private String password;

of course, with their respective getters and setters, this pojo will be another java class, for example: Recipient.java. Then back to your main class, you can create a List object from Recipient, like this

    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);

    }

if you want to show all the data you've saved in lstRecipient you can simply make a for statement to flush the data

    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         

    }

I hope that provide some help.

Brijesh Bhatt
  • 3,810
  • 3
  • 18
  • 34
Zenith
  • 1
  • 1
  • Thanks for your help guys. I just started so was not really familiar so am I suppose to create another database table ? @Brijesh Bhatt – BeginningMyJava Apr 10 '15 at 06:27
0

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?

Community
  • 1
  • 1