unable to retrive the data from mysql using servlet using jdbc driver
Hi, i have a servlet program..to verify the login and redirect to correct html page on verification.
public class LoginServlet extends HttpServlet implements javax.servlet.Servlet
{
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException
{
// Get the requested name and the output writer.
PrintWriter out = response.getWriter ();
String username = request.getParameter("UserName");
String password = request.getParameter("Password");
//Used to instantiate a connection
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "rapax";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password1 = "ajay12";
Statement stmt = null;
ResultSet rs = null;
try
{
try
{
Class.forName(driver).newInstance();
}
catch(InstantiationException e)
{
}
catch(IllegalAccessException e)
{
}
con = DriverManager.getConnection((new
StringBuilder()).append(url).append(dbName).toString(),userName,password1);
System.out.println("Connected to the database");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM login where
username="+username+" and password="+password);
// displaying records
if(rs.next())
{
String uname=rs.getObject(1).toString();
String pwd=rs.getObject(2).toString();
response.sendRedirect("http://localhost:8080/sessionAction.html");
}
else
{
out.println("\n\nInvalid Login\n");
rs.close();
response.sendRedirect("http://localhost:8080/login.html");
}
// throw new IOException(new IOException("Error"));
}
catch (SQLException e)
{
}
catch (ClassNotFoundException e) {
}
finally
{
try
{
if(rs!=null)
{
try{
rs.close();
}
catch(NullPointerException e)
{
}
}
rs = null;
if(stmt!=null)
{
try
{
stmt.close();
}
catch(SQLException e)
{
}
}
stmt = null;
if(con!=null)
{
try
{
con.close();
}
catch(NullPointerException e)
{
}
}
con = null;
}
catch (SQLException e)
{
}
out.close();
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
ServletException,IOException
{
doPost(request,response);
}
}
.i am unable to redirect..here is the code..pls help me THANK YOU
View Answers
October 25, 2011 at 12:38 PM
Ads
Related Tutorials/Questions & Answers:
Advertisements
Request URl using Retrive data from dtabase
Request URl
using Retrive data from dtabase
Using With GWT
the user can create an event. In the create page, we have three buttons. Save as draft... the contents
from the db based on the event id. But this jsp url should
retrive data from database using jsp in struts?
retrive data from database
using jsp in struts? *search.jsp*
<... searchProduct(SearchDTO sdto) {
String query="select *
from product...());
Connection con=DriverManager.getConnection("
jdbc:oracle:thin:@localhost:1521
get info from mysql using jsp and servlet
the user to key in their email address
from mysql database by
using servlet and jsp too...get info
from mysql using jsp and servlet HELLO! I wanna create...;
String url = "
jdbc:
mysql://localhost:3306/";
String dbName = "register";
String
url parameter using retrive data from database in jsp
url parameter
using retrive data from database in jsp the user can create an event. In the create page, we have three buttons. Save as draft... the contents
from the db based on the event id. But this jsp url should be a public
url parameter using retrive data from database in jsp
url parameter
using retrive data from database in jsp The user can create an event. In the create page, we have three buttons. Save as draft... the contents
from the db based on the event id. But this jsp url should be a public url
Exporting data from mysql into csv using jsp
Exporting
data from mysql into csv
using jsp Hi friends.... I want to export the
data from mysql to csv file
using... i am having 30 columns in my database.. Eg- text1,text2,text3,....,upto text30... i want to export this
data
Unable to upload a file to mysql database using struts1
Unable to upload a file to
mysql database
using struts1 Hi,
Below...=DriverManager.getConnection("
jdbc:
mysql://localhost/test","root","");
System.out.println...="multipart/form-
data">
Select a File :<html:file property="file"/>
<
not able to connect to mysql using.. jdbc
not able to connect to
mysql using..
jdbc i am not able to connect to
mysql using jdbc ..
is there any classpath that i need to set..because i am
using mysql-connector-java jar file..to connect to
mysql..
Pls provide the steps
retrieve related data from database using jsp and mysql
retrieve related
data from database
using jsp and mysql Hi sir,
please give some example of jsp code for retrieving
mysql database values in multiple dropdown list. if we change a value in a dropdown its related value must
retrive article from sql databse and show using php
retrive article
from sql databse and show
using php hello sir
i have sql database which i store articles.i want to show these article on web page
using php. my field are image,title,summary,content id. plz provide me
how to insert data into database using jsp & retrive
how to insert
data into database
using jsp & retrive Hello,
I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password