Comment on Tutorial - Struts 1 vs Struts 2 By jcarreira, adrian deccico
Comment Added by : Prajwal
Comment Added at : 2011-11-08 10:19:58
Comment on Tutorial : Struts 1 vs Struts 2 By jcarreira, adrian deccico
Can any one help me writing the code...
In struts2... i want to validate username and password through database..
import com.opensymphony.xwork2.ActionSupport;
import java.sql.*;
public class Retrieve extends ActionSupport
{
public String execute() throws Exception
{
String url = "jdbc:mysql://localhost:3306/";
String dbName = "login";
String driverName = "com.mysql.jdbc.Driver";
String userName = "root";
String passWord = "12345";
Connection con=null;
try{
Class.forName(driverName).newInstance();
con=DriverManager.getConnection(url+dbName, userName, passWord);
System.out.println("Connected database successfully...");
}
catch(Exception e){
System.out.println(e.getMessage());
}
try{
String username=getUsername();
String password=getPassword();
String sql = "select * from user";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
// System.out.print("Username :" + rs.getString(1)+ " ");
// System.out.println("Password :" + rs.getString(2));
if (this.username.equals("admin")&& this.password.equals("admin"))
{
System.out.print("Username :" + rs.getString(1)+ " ");
System.out.println("Password :" + rs.getString(2));
return "success";
}
else
{
return "error";
}
}
}
catch(SQLException s){
System.out.println(s);
}
return SUCCESS;
}
private String username= null;
private String password= null;
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}
Here in above code i have hardcoded the username and password but i want database to validate the user credentials..
help me ASAP
View Tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Archived Comments
1. If you are working with the multi-threaded program
View Tutorial By: Prithvi at 2010-01-07 10:24:12
2. Pl send some sample program for speech to text wit
View Tutorial By: gokul at 2012-09-27 10:28:19
3. thanks for this example but i want the whether th
View Tutorial By: Rupesh Chavan at 2010-03-14 07:36:31
4. Very good tutorial!
View Tutorial By: Herve at 2011-04-04 08:06:21
5. could u help me i want to integrate the paypal sys
View Tutorial By: Anand at 2011-01-17 21:59:25
6. better if it is explained with output of the progr
View Tutorial By: dinesh at 2013-05-05 13:57:21
7. Thank you. It is very good.
View Tutorial By: tapes pra at 2011-12-08 09:23:31
8. add reference -> .net -> 'Microsoft.Office.
View Tutorial By: Ravi at 2011-08-27 12:17:36
9. Nice one. I havn't thought of this before.
View Tutorial By: Aniket Sawant at 2013-04-09 05:40:58
10. pls give us aprogram of postfix and infix using st
View Tutorial By: lost_hope1111 at 2009-02-13 01:48:37