Home Answers Viewqa JSP-Servlet JSP- common dbase connection

 
 


vasu
JSP- common dbase connection
3 Answer(s)      4 years and 5 months ago
Posted in : JSP-Servlet

View Answers

February 5, 2009 at 3:53 AM


Hi vasu,


I am sending login application connected with database. Please implement following code:


<html>
<title>login application in jsp</title>
<head>

<script type="text/javascript">

function validateForm(theForm){



if(theForm.userid.value==""){

//Please enter username

alert("Please enter User Name.");

theForm.userid.focus();

return false;

}
if(theForm.password.value==""){
//please enter passward
alert("Please enter Password.");
theForm.password.focus();
return false;
}

return true;
}
</script>
</head>

<body>
<br>
<br/>
<center>

<table border="1" width="400px" bgcolor="pink" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<form method="POST" action="loginAction.jsp" onsubmit="return validateForm(this);">

<h2 align="center"><font color="red">Login Application in JSP</font></h2>
<table border="0" width="350px" cellspacing="2" cellpadding="4">
<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>
<center>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</center>
</form>
</td>
</tr>
</table>
</center>
</body>

</html>

February 5, 2009 at 3:54 AM


Action file :


<%@ page language="java" import="java.sql.*" import="java.util.*" %>

<%



String userid = request.getParameter("userid");

String password = request.getParameter("password");



Connection con = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String pass="amar123";

try {

Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,pass);

Statement st = con.createStatement();

String strQuery = "select * from login where userid='"+userid+"' and password='"+password+"'";

out.println(strQuery);

ResultSet rs = st.executeQuery(strQuery);



while(rs.next()){

if((rs.getString(1).equals("admin")) && (rs.getString(2).equals("admin")))

{

session.setAttribute("userid",userid);

response.sendRedirect("userForm.jsp");
}


if((rs.getString(1).equals("user")) && (rs.getString(2).equals("user")))

{

session.setAttribute("userid",userid);

response.sendRedirect("registrationForm.jsp");
}

else{

response.sendRedirect("loginForm.jsp");

}


}

System.out.println("Connected to the database");

con.close();



} catch (Exception e) {

e.printStackTrace();

}

%>


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

Visit for more information:

http://www.roseindia.net/jsp/

Thanks.

Amardeep

February 6, 2009 at 2:48 AM


Hi! vasu

use singleton design pattern. This should help u , if am not wrong.

If performs some thing like a static object & in that implement a logic which if d connection is present it should return else d existing obj will be returned.

Regards,
Krishna.Kantimahantu









Related Pages:
Dbase connection - JSP-Servlet
Dbase connection  Hi! how to write common dbase connection for all JSP pages. In how many ways we can write this... send me any code if u have.......... Thanks in advance
JSP- common dbase connection - JSP-Servlet
JSP- common dbase connection  Hi! Thanks for your suggession regarding Live news... Now it is working.... I have a small doubt in dbase connection.... I want to write only one dbase connection and i want to call
Common connection in JSP - JSP-Servlet
Common connection in JSP  Hi I am creating an JSP application. I want to use a common JSP page so that I can include it into other pages and get connection to database. I am able to get connection in other(common) JSP
dbase store - JSP-Servlet
dbase store  HI! In my project i have to store phone number in dbase. i used numeric (11,0) as data type for phone number. When i am trying to store...". If i am storing 9 numbers it is storing in dbase... What's wrong
connection
connection   How to get connected to my database using jsp   Please visit the following links: http://www.roseindia.net/jsp/connectjspwith_mysql.shtml http://www.roseindia.net/jsp/displaydatafrom_database1.shtml http
how can i use one dbase conection in serveral pages - JSP-Servlet
how can i use one dbase conection in serveral pages  Hi! Thanks for sending code... But my actual requirement is In my project i am writing dbase connections many times whereever i need in several pages. How can I avoid
jsp connection with oracle.
jsp connection with oracle.  I want to connect with jsp to oracle,,,plz send me the codes
jsp connection with oracle.
jsp connection with oracle.  I want to connect with jsp to oracle,,,plz send me the codes
connection of jsp with mysql - JSP-Servlet
Example of connection between JSP and MYSQL  Need an example of connection between JSP and MYSQL
JSP - JSP-Servlet
JSP  Hi! In my JSP page I am entering values and submitting the values. In common way I have to receive those values in another JSP using... to receive values in second page. I want to write dbase connections
jsp connection to db2
jsp connection to db2  hello friends i have a project to do in jsp using db2 database can anyone please help me in connecting a jsp page to db2 database?? please frienda help me
Connection Pooling - JSP-Servlet
Connection Pooling  Hi All, Iam new to Connection Pooling in Java. I need to create connection pooling for my MySQL Database with JSP using Bean... Connection con=null; public static Connection getConnection() { try
connection with database - JSP-Servlet
and the connection with the database using jsp code, I get exceptions that I have... with java code. Is there any other way to establish a connection with database in jsp...connection with database  I tried the DSN and connection
connection of jsp with mysql - JSP-Servlet
connection of jsp with mysql  can anybody tell me about connection of JSP with MYSQL? and also tell me which version is compatible with tomcat 4.1 i am using tomcat 4.1, MYSQL 5.0 but i have problem with connection
jsp/mysql connection
jsp/mysql connection  I am puttng the following files in the lib folder of jdk to connect jsp and mysql and in the lib folder of tomacat and in the lib folder of project of netbeans but I am unable to to connect jsp and mysql
jsp/mysql connection
jsp/mysql connection  I am puttng the following files in the lib folder of jdk to connect jsp and mysql and in the lib folder of tomacat and in the lib folder of project of netbeans but I am unable to to connect jsp and mysql
JSP - MySQL - Connection
JSP - MySQL - Connection  I can't connect mysql using jsp in my server.It shows some error like this. """ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received
Connection pooling
Connection pooling  Sir, In my project i want to implement connection pooling with ms-sql server 2005. i wrote the code in JSP like this... <% Connection con=DbCon.getConnection(); Statement stmt
connection - JDBC
connection  how to connect server pages to mysql  Hi Friend, To learn how to connect MySql to JSP, please visit the following link: http://www.roseindia.net/jsp/connect-jsp-mysql.shtml Thanks
common database jsp file for all the jsp files in the application
common database jsp file for all the jsp files in the application  hi... use of this single jsp file while connecting to database rather than writing connectivity code in all the jsp pages . send me the code for that . thanks
database connection
database connection  how to connect the jsp page with database
jdbc connection
jsp --%> <%@page import="java.sql.Statement"%> <%@page import..." pageEncoding="UTF-8"%> <%-- JSP Page View... { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection
Use of Connection Pooling - JSP-Servlet
Use of Connection Pooling  Dear Friends i want to use connection pooling in my jsp page i created one connectionPooling.java is : package... Connection con=null; public static Connection getConnection() { try
server database connection - JSP-Servlet
ODBC For Oracle}","scott","tiger"); But how to get the connection from..." in that case how we will get the database connection   Hi Friend
connection with mysql with jstl - JSP-Servlet
connection with mysql with jstl  hi, i m working on jstl . i hv done connection in MS -Access with JSTL . The code is working well. but when i am trying to connect database with mysql 5.0 it is creating problem. Plz tell me
connection with MySQL to java.
connection with MySQL to java.   how to connect MySQL database with jsp
Draw graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
Some Common Types of FTP Commands
it is important to know some common types of FTP commands. Though, many FTP.... To start with the most common basic FTP commands let us first know some... stands for local filename rfilename stands for remote filename Some common
error in driver connection
Connection con=null; ResultSet rst=null; Statement stmt=null; but this is the syntax for aceesing database in jsp
jdbc connection issues
jdbc connection issues  Hello. kindly pls help in this issue...i have created 11 jsp form wit some attributs in it also created 11 tables... tables with only one jdbc connection program...if possiable pls post a sample code
Connection
Connection  What is Connection
Connection to database - Java Beginners
Connection to database   HI I have just Started working on a Project on Jsp We hve some JSP Pages & trying to connect to our Database . We... a link where u can see how to connect jsp to mysql: http://www.roseindia.net/jsp
Connection pooling - Java Beginners
Connection pooling  Respected Sir/Madam, I am Ragavendran.R.. I need some clarification on what connection pooling is? Moreover can u provide me an example of how to implement connection pooling concept
How to make the horizontal navigation bar common to all pages?
How to make the horizontal navigation bar common to all pages?  Hi, I did a project using JSP. And now I am having issue on how to make the navigation bar common to all the jsp pages. I have a header, and navigation bar and want
connection
connection   how to make multiple database connection using jdbc
Connection to jdbc - Java Beginners
Connection to jdbc  I need to populate a listbox in jsp with values from Postgresql JDBC. i used the following code... but its not working... can u suggest me with the correct solution. my.jsp my form
JSP - JSP-Servlet
JSP  what are the other options to connect the dbase from JSP page except beans. I dont want to write connection in each and every page.. Is there any other way. Pls... help me........  Hi friend, Use Hibernate
Java Thread not geting Connection pool - JSP-Servlet
Java Thread not geting Connection pool  Hi All, Please help me in following problem. I have database connection on server using connection pool... while getting database connection in Background process. I am passing
How to design https connection page using JSP
How to design https connection page using JSP  Hi, I have a project in which a page requires https secure design to process the payment. Since... JSP Thank you
jsp to cassandra datbase connection by using eclipse
jsp to cassandra datbase connection by using eclipse  sir i want to connect the apache cassandra datbase by using cql query language. i am success by using simple java application.now my task is to interact with cassandra
combo box connection
combo box connection  how to provide connection between three combo... box is my subjects.what's the coding to provide the connection between this three...--"); Class.forName("com.mysql.jdbc.Driver"); Connection con
code for jsp to db connection using jdbc
code for jsp to db connection using jdbc  please send me the code...;form method="post" action="http://localhost:8080/examples/jsp/insert.jsp"> <...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc
connection
the connection with the available port on the host machine: import java.net.... the connection was not established. Predict the output of the preceding code. Explain why the connection cannot be established
error oracle database connection?
error oracle database connection?  hi now i am trying to connect...; PreparedStatement stmt=null; Connection con =null; ResultSet rs=null... method stub } } desing jsp page; newuser_reg.jsp <%@ page language="java
java multiple users with single connection - JSP-Servlet
it for multiple users who uses a single connection to the database simultaneously... of the above websites uses a single connection with multiple users. n...{ Class.forName("com.mysql.jdbc.Driver"); Connection con
Connection pool in Tomcat 6 - JDBC
Connection pool in Tomcat 6  Hi All, Any one please tell me how to implement connection pooling in Tomcat 6 and MySQL 5.0.1b. Thanks...://www.roseindia.net/jsp/jspfundamentals.shtml Hope that it will be helpful
JSP - JSP-Servlet
JSP  Thanks for your reply....regarding dbase connection using beans. i am using tomcat 5.0. I want to know where i have to place this class file. when i am trying to place this class file(DBcon.java) in WEB-INF classes
java oracle connection problem - SQL
java oracle connection problem  I have successfully made connection... JSP. But the codes that i have tried for fetching the data are not working even though they do not show any error.Can you kindly provide me a code written in JSP