File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes the developer made JDBC calls in every bean.what to change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "the developer made JDBC calls in every bean.what to change" Watch "the developer made JDBC calls in every bean.what to change" New topic

the developer made JDBC calls in every bean.what to change

prasanna pati
Ranch Hand

Joined: Jan 29, 2005
Posts: 46
Basically I am a tester for J2ee application ( struts ). I have got a developed project in which the developer made Jdbc calls in his/her every beans validate method . He made atleast 30 beans and almost every bean is similar somewhat similar to this : ( see below )

these are all he/she made in ActionForms . So what should I suggest him/her ?

now see the actionForms >>> ( I am pasting only 1 example )

package beanpack;
import javax.servlet.http.HttpServlet;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;

import javax.servlet.http.HttpServlet;

public class Loginbean extends HttpServlet

private String name, pass;

public Loginbean() {
name = null;
pass = null;

public Loginbean(String nm, String pwd) { = nm;
this.pass = pwd;


public boolean validation() {

try {
Connection con = DriverManager.getConnection("jdbc dbc:MyDSN");
Statement st = con.createStatement();
String stp = new String("select * from kenji where username='"
+ getName() + "' and password='" + getPass() + "'");
ResultSet rest = st.executeQuery(stp);

System.out.println("... " + stp);
if (
return true;

} catch (ClassNotFoundException e) {
} catch (SQLException e) {

return false;


public String getName() {
return name;

public void setName(String name) { = name;

public String getPass() {
return pass;

public void setPass(String pass) {
this.pass = pass;



firstly he made everything hardcoded , next no-internal-comments .tell some other stuffs and what should I suggest him?
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Considering that it's not just the form beans, which you have to review, I'm sure reading up on one of the "Struts Best Practices" results will give you a lot of points.

Also, making JDBC calls from the form bean is a total NO-NO. It doesn't make sense to adopt a framework and then go about violating one of its fundamental requirements (that of separation of layers).

[ March 18, 2008: Message edited by: Anirvan Majumdar ]
[ March 18, 2008: Message edited by: Anirvan Majumdar ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd also suggest that you tell the developer to read up on the Data Access Object and Transfer Object patterns. These patterns are very useful in separating the layers in a database application.
[ March 18, 2008: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I would have to know how this class fit into the big picture to comment too much. What you are showing is not an "ActionForm". I do not understand what it is. It extends HttpServlet but it sure does not look like a servlet to me.

- Brent
I agree. Here's the link:
subject: the developer made JDBC calls in every bean.what to change
jQuery in Action, 3rd edition