Home Answers Viewqa JSP-Servlet java multiple users with single connection

 
 


nishi
java multiple users with single connection
2 Answer(s)      3 years and 8 months ago
Posted in : JSP-Servlet

View Answers

September 10, 2009 at 12:18 PM


Hi Friend,

Try the following code:
1)selectUser.jsp:

<html>
<form action="login.jsp" method="post">
Select User Type: <select name="userType">
<option value=""><--Select--></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<input type="submit" value="Submit">
</form>
</html>

2)login.jsp:

<%@ page language ="java" %>
<%
String userType=request.getParameter("userType");
%>
<html>
<body>
<form name="f1" method="post" action="..//LoginServlet">
<table align="center">
<tr>
<td>User Name</td><td><input type="text" name="user" ></td>
</tr>
<td>Email ID</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login"></td>
</tr>
</table>
<input type="hidden" name="type" value="<%=userType%>">
</form>
</body>
</html>

3)LoginServlet.java:

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

public class LoginServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String username=request.getParameter("user");
String email=request.getParameter("email");
String userType=request.getParameter("type");
String table=userType.toLowerCase();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
Statement stmt=con.createStatement();
ResultSet rs=null ;
DatabaseMetaData meta = con.getMetaData();
rs = meta.getTables(null, null, null, new String[]{"TABLE"});
String tableName=null;
while (rs.next()) {
tableName = rs.getString("TABLE_NAME");
if(table.equals(tableName)){
out.println("<br>");
String strquery = "select * from "+tableName+" where username='"+username+"' && email='"+email+"'";
rs=stmt.executeQuery(strquery);
out.println("<table>");
while(rs.next()){
out.println("<tr><td>UserName:</td><td><input type='text' value='"+rs.getString(2)+"'></td></tr>");
out.println("<tr><td>Email:</td><td><input type='text' value='"+rs.getString(4)+"'></td></tr>");
out.println("<tr><td>Phone:</td><td><input type='text' value='"+rs.getString(5)+"'></td></tr>");
out.println("<tr><td>Address:</td><td><input type='text' value='"+rs.getString(6)+"'></td></tr>");
}
out.println("</table>");
}
}
con.close();
}
catch(Exception e){
out.println("exception occured" +e);
}
}
}

Thanks


September 10, 2009 at 12:24 PM


Hi Friend,

For the above code,we have created four tables A,B,C,D in Database.

Hope that the above code will be helpful for you.
Thanks









Related Pages:
java multiple users with single connection - JSP-Servlet
java multiple users with single connection  hi, my problem... 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
reading multiple files from a directory and writing them into a single file
reading multiple files from a directory and writing them into a single file   i have done the following code but the every time i write to the single... this: /*this program reads multiple files * from a single directory. */ package elite.tech.com
A connection pool with multiple user ID.
A connection pool with multiple user ID.  Can I set up a connection pool with multiple user IDs? The single ID we are forced to use causes problems when debugging the DBMS
multiple dropdowns in single page - JSP-Servlet
multiple dropdowns in single page  i have a jsp page having drop down menus generated based on the number of request send and name of the drop down..."); } Statement stmt=null; Connection con1=null; ResultSet
multiple submits, single form.
multiple submits, single form.  is it possible to use multiple submit buttons in a single form?   Thank you
single frame coding in java
single frame coding in java  sir, i am a beginner in java.i want to do a desktop application in java in which a single frame satisfies all needs.but i want changes in that frame only.how can i solve this?i think multiple frames
Multiple submit nuttons in single xhtml form - Java Server Faces Questions
Multiple submit nuttons in single xhtml form  Hi, I am facing problem in my JSF application, where in single page , we have two submit buttons. If any one of the button is clicked , then entire form is submitted. How to avoid
connection
connection   how to make multiple database connection using jdbc
Multiple submit buttons in single xhtml form - Java Server Faces Questions
Multiple submit buttons in single xhtml form  Hi all, Here I am attaching the source of the page , which containig two submit buttons. Somebody suggested to keep eaxh button in different form. I am new to JSF, can anyone split
Use multiple catch statement in single jsp
Use multiple catch statement in single jsp       In java a single try can have multiple...; <HEAD> <TITLE>multiple catch in single jsp program<
Java jdbc connection
Java jdbc connection  Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing the project bus route network. i have fields source, destination and stages. for example...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing the project bus route network. i have fields source, destination and stages. for example...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing the project bus route network. i have fields source, destination and stages. for example...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing the project bus route network. i have fields source, destination and stages. for example...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing the project bus route network. i have fields source, destination and stages. for example...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing the project bus route network. i have fields source, destination and stages. for example...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array  i am using netbeans 7.0 ,with struts 1.3.8 and i want to insert multiple images in mysql database ,with use
Connection pooling - Java Beginners
in JAVA with the help of below mentioned codings: I need all the queries in a single...Connection pooling  Respected Sir/Madam, I am Ragavendran.R.. I need some clarification on what connection pooling is? Moreover
executing multiple sql statements on the single button click...
executing multiple sql statements on the single button click...  how can i frame a code on the click of a button to insert data into a table as well as to retrieve records from the same table in another form
executing multiple sql statements on the single button click...
executing multiple sql statements on the single button click...  how can i frame a code on the click of a button to insert data into a table as well as to retrieve records from the same table in another form
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns  i am 3rd year cs student in ethiopia. i have...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql
TO connect multiple database
TO connect multiple database  How to connect several database from a single application in java depending upon the user input it will connect to that database
Uploading a single file by using JSp
Uploading a single file by using JSp  u have said about submit button...;%@ page language="java" %> <HTML> <FORM ENCTYPE="multipart/form-data...;/tr></table> <% Connection connection = null; String connectionURL
Interact with connection pools to obtain and release connections
it. You can use a cached unshared connection handle across multiple... Inefficient use of your connection resources. For example, if within a single..., the component calls a utility class (Java object) which gets a connection
help me plz:-Merge multiple jasper files into Single one
help me plz:-Merge multiple jasper files into Single one  how to Merge multiple jasper files into Single one word doc
Y No Multiple Inheriatance in Java - Java Beginners
into a single class is known as multiple inheritance. Java does not support..., Why java doesn't support multiple inheritance.  Hi Multiple... the interface. In Java Multiple Inheritance can be achieved through use of Interfaces
Java single threaded model
Java single threaded model  How single threaded model works after implementation in class, basically architecture point of view
Multiple values for a single parameter
Multiple values for a single parameter       In our program it may be that we may have multiples values for a single parameter like in checkboxes. We are going to make one
multiple JComboBoxes using with JDBC
multiple JComboBoxes using with JDBC  how to use JComboBoxes...(){JFrame f = new JFrame("Frame in Java Swing");JLabel label1=new...{Class.forName("com.mysql.jdbc.Driver");Connection con
Database Connection Pooling (DBCP)
and quicker response using the available connections as making new connection is very... the database connection for processing the request send by the clients and at a single time, myriad numbers of request are send for retrieving the data
Connection pooling
in a pool. This pool is called the Connection pool. In your Java program you can...) it. Popular connection pooling software in Java is Apache DBCP. You can learn...Connection pooling  hii, What is Connection pooling?   
enable users to enter names - Java Beginners
enable users to enter names  this is the code for tic tac toe game, i want users can save their name as player X and player O, but I do not know how? can you give me some tips? package threeTsGame; import java.awt.
DataBase Connection
DataBase Connection  How to connect java and Oracle 10g? Tell me Jdbc connection
Java read multiple files
Java read multiple files In this section you will learn how to read the data of multiple files. Here we have created four files that includes information... into a single file. Here is the code: import java.io.*; import java.util.*; public
JDBC Connection Example
; } JDBC Connection Example JDBC Connection is an interface of java.sql.*;  package. An connection object represents a connection with specific database. A single application can have more than one Connection object with a single
Connection pooling
the following link: Connection Pooling In Java Thanks...Connection pooling  Sir, In my project i want to implement connection pooling with ms-sql server 2005. i wrote the code in JSP like
multiple inheritance.
multiple inheritance.  hello, can java support multiple inheritance???   hi, java does not support multiple inheritance
Connection to Database
about 10 users at the same time, I get the connection error. If MySQL...Connection to Database  Hello, I have a website with more than 50.... However, most of times my web pages displays the error message" Too many Connection
java connection leak
java connection leak  How to check the connection leak in Java
JTree Multiple Selection
either single-item or multiple-item. TreeSelectionModel: This is an interface... Enable and Disable Multiple Selections in a JTree Component... will learn how to enable and disable the multiple selections in a JTree
multiple inheritance
multiple inheritance  why java doesn't support multiple inheritance? we can achieve this by using interface but not with classes? what is the main reason that java community implemented like
JDBC connection
JDBC connection  ![alt text][1]I got exception in Connecting to a MySQL Database in Java. The exception is ClassNotFoundException:com.mysql.jdbc.Driver wat is the problem
connection retry in java
connection retry in java  How to retry the connection automatically once it get disconnect..?   Connection connection = null; while (connection == null) { try { connection = DriverManager.getConnection(url

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.