• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Spring Struts implementation for Database conncetion problem in Login module

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic