Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to connect jsp to mysql
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragini Shukla
how to connect jsp to mysql
2 Answer(s)      6 years and 6 months ago
Posted in : Java Beginners



Advertisement
View Answers

June 4, 2008 at 7:27 PM


Hi ragini,


This is form code ,

<html>
<head>
<title>Insert into database</title>

</head>

<body>

<table border="1" width="50%" bgcolor="pink" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<form method="POST" action="/examples/jsp/LoginAction" >

<h2 align="center">login page</h2>
<table border="1" width="100%">
<tr>
<td width="50%"><b>User Name:</b></td>
<td width="50%"><input type="text" name="userid" size="20"/></td>
</tr>
<tr>
<td width="50%"><b>Password:</b></td>
<td width="50%"><input type="password" name="password" size="20"/> </td>
</tr>

</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>

</form>
</td>
</tr>
</table>

</body>
</html>

--------------------------------

web.xml

<servlet>
<servlet-name>loginaction</servlet-name>
<servlet-class>javacode.LoginAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginaction</servlet-name>
<url-pattern>/jsp/LoginAction</url-pattern>
</servlet-mapping>



June 4, 2008 at 7:29 PM


This is servlets code,

package javacode;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class LoginAction extends HttpServlet {
private Connection con;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";
public void init()throws ServletException {
System.out.println("INIT");
try {
Class.forName(driver);
con=DriverManager.getConnection(url+db,userName,password);
}//try
catch(Exception e){
e.printStackTrace();
throw new ServletException("unable to get database cooenction.");
}//catch

}//init
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException {

System.out.println("in service");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
PreparedStatement ps=null;
try{
String userid=req.getParameter("userid");
String pass=req.getParameter("password");
if(userid==null||userid.equals("")||pass==null||pass.equals("")){
out.println("<html><body>");
out.println("<i>UserName/Password are empty,they cannot be empty </i>");
out.println("</body></html>");
return;
}//if
ps=con.prepareStatement("select * from login where userid=? and password=?");
ps.setString(1,userid);
ps.setString(2,pass);
ResultSet rs=ps.executeQuery();
out.println("<html><body>");
if(rs.next())
out.println("Successfully login");
else
out.println("username and password not currect, please try again.");
out.println("</body></html>");
}//try
catch(Exception e){
out.println("unable to process the request please try later");
}//catch
finally {
try{
ps.close();
}
catch(Exception e) {}
}//finally
}//doget
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
doGet(req, res);
}
public void destroy() {
System.out.println("In destroy");
try {
con.close();
}
catch(Exception e) {
System.out.println(e);
}
}//destroy
}

------------------------------------------------

Read for more information.

http://www.roseindia.net/servlets

Thanks


Related Tutorials/Questions & Answers:
How to connect mysql with jsp
How to connect mysql with jsp  how to connect jsp with mysql while using apache tomcat
how to connect jsp to mysql - Java Beginners
how to connect jsp to mysql  I m new in Mysql and JSP i m ceating.java file using bean file for connectivity but i m not able to connect jsp... me hw to conncet jsp with mysql this is connection file package connect
Advertisements
Connect JSP with mysql
; This query creates database 'usermaster' in Mysql. Connect JSP with mysql : Now in the following jsp code, you will see how to connect... Connect JSP with mysql   
Connect JSP with mysql
you how to connect to MySQL database from your JSP code. First, you need... Connect JSP with mysql   ... database in my sql command prompt) 2. Connect JSP with mysql
how to connect mysql with JDBC - JDBC
how to connect mysql with JDBC  I have created three tables in the database MYsql, i have to connect them now using JDBC, can u please suggest me...(); } } Thanks Rajanikant  Hi friend, To mysql connect using JDBC
how to connect mysql from gui?
how to connect mysql from gui?  i am unable to connet to mysql server from my projet that is gui for mysql...can anyone help me in this...its urgent? i have to connet to mysql from gui..   Hi Friend, Try the following
how to connect to database in php using mysql
how to connect to database in php using mysql  how to connect to database in php using mysql
how to connect mySql drivers into eclipse(configuration)?
how to connect mySql drivers into eclipse(configuration)?  how to connect mySql drivers into eclipse(configuration)? I need the configuration in eclipse. what do i have to download from mySql and just downloading is enough or do
problem connect jsp and mysql - JSP-Servlet
problem connect jsp and mysql  hello, im getting an error while connecting jsp and mysql. I have downloaded the driver mysql-connector... Software Foundation\Tomcat 5.5\common\lib\mysql-connector-java-2.0.14.jar
Mysql connect
Mysql connect  i can have a mysql database file and mysql-connector-net .but i have not mysql database. how to connect vb.net thsis database.(C:\Documents and Settings\Admin\My Documents\VB.NET\Stock delna\STC.sql ). plz help me
how to connect j2me program with mysql using servlet?
how to connect j2me program with mysql using servlet?  my program...(); String userid=connect(user.toLowerCase().trim(), pwd.toLowerCase().trim... String connect(String user,String pwd){ String db="mobileapp
Using javabeans to connect mySQL database on a jsp page - JSP-Interview Questions
Using javabeans to connect mySQL database on a jsp page  Hi, Am doing my project and I don't know how to connect a jsp page to a mySQl database...; Connecting a JSP page to MYSQL Database using JavaBean File Name: beancode.java
mysql_connect arguments
mysql_connect arguments   How many arguments a mysql_connection function required to connect to the database?   ?mysql_connect? function... And if the given arguments are correct it will connect to the database and print
how to connect to MS access database in JSP?
how to connect to MS access database in JSP?  how to connect to MS access database in JSP? Any seetings/drivers need to be set or installed before... DSN will get created. 6) Restart your server and run your jsp code. Here is your
How to connect
How to connect  how to connect to a remote host using jsp? We need to update files to the database of the application on the local machine from the updated database on our webpage
How to connect to MySql Database from Servlet?
; font-weight: bold; } How to connect to MySql Database from Servlet... will show you how to connect to MySQL database and perform select operation. You will learn the JDBC steps necessary to connect to the MySQL Database and execute
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
How to connect to dao n bean classes with jsp
= totalvillagearea; } } **how to connect with this edao and ebean pkg with my jsp...How to connect to dao n bean classes with jsp  I have made this edao...; </table> <!-- End of New Village Registration --> <jsp:useBean
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt...."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt...."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
how to connect the database using hibernet through servlet/jsp through form
how to connect the database using hibernet through servlet/jsp through form  plz give me the reply   Hi Friend, Please visit the following link: http://www.roseindia.net/jsf/myfacesspring/loginRegistration.shtml Hope
connect to the database from JSP
connect to the database from JSP  How do you connect to the database from JSP?   A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets
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
how to connect webcam in html
how to connect webcam in html  how to connect webcam in html.emphasized text
need help....how to connect and disconnect multiple databases(databases created in mysql) using java and my sql
need help....how to connect and disconnect multiple databases(databases created in mysql) using java and my sql  i am working on a project... to know that how to query multiple databases(databases created in my mysql) so
How to connect with database
How to connect with database  jdbc connection
can't connect to MySQL Server(10060) - JDBC
can't connect to MySQL Server(10060)  Hii Sir, I am working with a jsp project with MySQL as server. Now i want to host my application. I am... MySQL front end. Can we connect to the MySQL server using the I.P address
how to fetch image from mysql using jsp
how to fetch image from mysql using jsp  how to fetch image from mysql using jsp
error call to undefined function mysql_connect
error call to undefined function mysql_connect  what is error call to undefined function mysql_connect
Advertisements
 

 

 

DMCA.com