Two Laptop Bag*
The moose likes Spring and the fly likes Spring Struts implementation for Database conncetion problem in Login module Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Struts implementation for Database conncetion problem in Login module" Watch "Spring Struts implementation for Database conncetion problem in Login module" New topic
Author

Spring Struts implementation for Database conncetion problem in Login module

sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear All,
I am a beginner of using spring concept. I am writing a small Login program using Struts and spring.I am just hard coded the string if the login id and Password is matching then it will go to welcome.jsp.It is working fine.

With this logic in BusinessDelegate.java it is working properly.
public String validateUser(String userName, String password) {
String data=null;


if(userName.equals("admin") && password.equals("123")) {
return "success";
}


return "failure";
}

I am calling validateUser() in LoginAction.java file.

target = businessDelegate.validateUser(loginForm.getUserName(),loginForm.getPassword());

But I want it should check with database level and if the login id and password matching then it will go to welcome page.

How can I write the syntax in BusinessDelegate.java so that it should work.
Like

private JdbcTemplate jdbcTemplate;

public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public String validateUser(String userName, String password) {


jdbcTemplate.queryForList("select login_name,password from ABC_USER where login_name='"+userName+"',password='"+password+"'");


if(rs.next())
{
return “success’;
}
Else
return “failure”;
}


[b]ApplicationContext.xml
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- <property name="driverClassName" value="com.mysql.jdbc.Driver"/>-->
<!-- <property name="url" value="jdbc:mysql://192.168.10.75:3306/komal"/>-->
<property name="driverClassName" value="com.jnetdirect.jsql.JSQLDriver"/>
<property name="url" value="jdbc:JSQLConnect://192.188.48.28/database=ABC_TEST"/>
<property name="username" value="test"/>
<property name="password" value="test"/>
</bean>
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
</bean>
<bean id="nativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"/>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>

[b]




Please suggest/rectify my code how it should work with checking the value in database level and if successful login then goto welcome page.
LoginForm.java

LoginAction.java
}

BusinessDelegate.java

ApplicationContext.xml



Web.xml



Struts-config.xml






Please suggest me the syntax of code how my BusinessDelegate.java and ApplicationContext.xml conncet with database and checking the userid and password.

Thanks in advance.

Regards,
Sumanta Panda
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's a difficult message to read.

Is the issue that you don't know how to write Spring database code?
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear David,

My doubt is what is the piece of code or syntax i will write in BusinessDelegate.java so that it will check database level.
.
For example::



Please suggest.


Thanks for the understanding.
Regards,
Sumanta Panda
 
Consider Paul's rocket mass heater.
 
subject: Spring Struts implementation for Database conncetion problem in Login module