aspose file tools*
The moose likes JDBC and the fly likes Connection Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connection Bean" Watch "Connection Bean" New topic
Author

Connection Bean

vinu pillai
Greenhorn

Joined: Oct 05, 2001
Posts: 7
hi all,
How to make a bean for connecting to Database through JSP..???
I have no idea what bean are....i hard code the jdbc syntaxes in the scriptlet tag itself...but some say that making a connection bean is proper way to show the database results...
i don't know how to create bean ...can help me out to find the best tutorial links to JavaBeans..

Thanks..
VINU
Toyin Sogeke
Greenhorn

Joined: Oct 08, 2001
Posts: 14
Hello Sir,
Create javabean as follows:
// Assign page name, very important
package example.test;
public class LoginCheck {
private String userName = "";
private String passWord = "";
// Default constructor is required.
public LoginCheck() { }
// JavaBean needs setter and getter methods
public void setUserName(String user) {
this.userName = user;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
// You can define a method here with
// your database connection details.
public boolean authenticate(String user) {
return (this.username.equalsIgnoreCase(this.userName));
}
}
You can use a JavaBean as follows in a JSP:
<jsp:useBean id="loginBean"<br /> scope="page"<br /> class="example.test.LoginCheck">
<jsp:setProperty name="loginBean" property="*"/>
</jsp:useBean>
<%<br /> // You can call and use a JavaBean as follows:<br /> boolean isLoggedIn = loginBean.authenticate("RanchHand");<br /> %>
Hope this helps.
Cheers
Originally posted by vinu pillai:
hi all,
How to make a bean for connecting to Database through JSP..???
I have no idea what bean are....i hard code the jdbc syntaxes in the scriptlet tag itself...but some say that making a connection bean is proper way to show the database results...
i don't know how to create bean ...can help me out to find the best tutorial links to JavaBeans..

Thanks..
VINU


homeboy
vinu pillai
Greenhorn

Joined: Oct 05, 2001
Posts: 7
thanks buddy,
I will deploy it soon...
bye...
Thanks again
Originally posted by Toyin Sogeke:
Hello Sir,
Create javabean as follows:
// Assign page name, very important
package example.test;
public class LoginCheck {
private String userName = "";
private String passWord = "";
// Default constructor is required.
public LoginCheck() { }
// JavaBean needs setter and getter methods
public void setUserName(String user) {
this.userName = user;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
// You can define a method here with
// your database connection details.
public boolean authenticate(String user) {
return (this.username.equalsIgnoreCase(this.userName));
}
}
You can use a JavaBean as follows in a JSP:
<jsp:useBean id="loginBean"<br /> scope="page"<br /> class="example.test.LoginCheck">
<jsp:setProperty name="loginBean" property="*"/>
</jsp:useBean>
<%<br /> // You can call and use a JavaBean as follows:<br /> boolean isLoggedIn = loginBean.authenticate("RanchHand");<br /> %>
Hope this helps.
Cheers

 
jQuery in Action, 2nd edition
 
subject: Connection Bean