|
 |
pro_jsp thread: Passing more than 1 value to a bean
Message #1 by "Denis" <yahden@y...> on Thu, 19 Jul 2001 13:09:44 -0400
|
|
Hi, below is some code of a bean that I build that does an insertion in
a database
right now it insert only 1 thing the Last name if would like to add a
first name too
this
String sqlstatement = "Insert INTO People (Lastname) VALUES (?)";
would become
String sqlstatement = "Insert INTO People (Lastname,FirstName) VALUES
(?,?)";
and this
//pstmt.setString(2,FirstName);
would be uncommented
now how do i pass 2 values ( first + last name) into the bean ???
in the JSP page this is the code right now
<jsp:useBean id="SqlTry" class="Beans.SqlDataFour">
<jsp:setProperty name="SqlTry" property="message" value="joe" />
<jsp:getProperty name="SqlTry" property="message" />
</jsp:useBean>
How do I passs in 2 values to the bean
TIA
Denis
package Beans;
import java.sql.*;
public class SqlDataFour {
private String message = "";
public String getMessage() {
return(message);
}// end getSqlData()
public void setMessage(String message) {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:JspTest";
String user = "";
String password = "";
String sqlstatement = "Insert INTO People (Lastname) VALUES (?)";
try {
Connection con = DriverManager.getConnection(url, user, password);
Class.forName(driver);
PreparedStatement pstmt = con.prepareStatement(sqlstatement);
pstmt.setString(1,message);
//pstmt.setString(2,FirstName);
pstmt.executeUpdate();
if(pstmt != null) pstmt.close();
if(con != null) con.close();
}// end try
catch(ClassNotFoundException cnfe) {
System.err.println("Error Loading Driver " + cnfe);
}// end catch
catch(SQLException sqle) {
System.err.println("Error Connecting " + sqle);
}// end catch
this.message = message;
}// end setSqlData()
}// end SqlData
|
|
 |