java multiple users with single connection

java multiple users with single connection

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 Tutorials/Questions & Answers:
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
multiple submits, single form.
multiple submits, single form.  is it possible to use multiple submit buttons in a single form?   Thank you
Advertisements
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
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
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
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
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
Use multiple catch statement in single jsp
Use multiple catch statement in single jsp       In java a single try can have multiple...; <HTML> <HEAD> <TITLE>multiple catch in single
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
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
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
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
single selection of chechbox among multiple selection when in a loop.
single selection of chechbox among multiple selection when in a loop.  i am using cmd prompt to run and execute the java pgm. here i need your help that when in a loop i trying to choose single checkbox among multiple checkboxes
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
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
Create multiple pie chart in single frame using JFreeChart
Create multiple pie chart in single frame using JFreeChart... you how to create a multiple pie charts in a single frame in jsp page using.../Q", data);  final JFreeChart chart = 
Java jdbc connection
Java jdbc connection  Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection
How to insert multiple drop down list data in single column in sql database using servlet
How to insert multiple drop down list data in single column in sql database using servlet  i want to insert date of birth of user by using separate drop down list box for year,month and day into dateofbirth column in sql server
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
connection
connection   how to make multiple database connection using jdbc
how to insert multiple columns of a single row into my sql database using jsp
how to insert multiple columns of a single row into my sql database using jsp  hi sir, how to insert multiple columns of a single row into my sql database using jsp. when i click ADD ROW,rows are added.when i click submit
how to create users in LDAP using java?
how to create users in LDAP using java?  how to create users in LDAP using java
multiple inheritance - Java Beginners
multiple inheritance  Why java does not support Multiple Inheritance...)why java classes does not support Multiple Inheritance? JAVA CLASSES ONLY NOT SUPPORT MULTIPLE INHERITANCE.But Java Interfaces can support Multiple
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
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
java connection leak
java connection leak  How to check the connection leak in Java
multiple inheritance - Java Beginners
multiple inheritance  can u implement one class to more than one interface
Execution of Multiple Threads in Java
Execution of Multiple Threads in Java  Can anyone tell me how multiple threads get executed in java??I mean to say that after having called the start method,the run is also invoked, right??Now in my main method if I want
Does Java support multiple Inheritance?
Does Java support multiple Inheritance?  Hi, I am beginner in Java and trying to implement multiple inheritance in Java. But could not find any example. Does Java support multiple Inheritance? Thanks   Hi, Good
Does Java support multiple Inheritance?
Does Java support multiple Inheritance?  Hi, I am beginner in Java and trying to implement multiple inheritance in Java. But could not find any example. Does Java support multiple Inheritance? Thanks   Hi, Good
Does Java support multiple Inheritance?
Does Java support multiple Inheritance?  Hi, I am beginner in Java and trying to implement multiple inheritance in Java. But could not find any example. Does Java support multiple Inheritance? Thanks   Hi, Good
How to make the single click as double click in java
How to make the single click as double click in java  How to make the single click as double click in java... By clicking on a tab, the tab should respond as clicked twice i.e (double click on the tab/button)... Its very urgent
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
Does Java support multiple inheritance?
Does Java support multiple inheritance?  Hi, Does Java support multiple inheritance? thanks   hi, Please visit the following link: http://www.roseindia.net/java/language/inheritance.shtml Hope
connection with MySQL to java.
connection with MySQL to java.   how to connect MySQL database with jsp
retrieve multiple columns values from multiple csv files in java
retrieve multiple columns values from multiple csv files in java  Suppose there is folder in C:\fileupload which contains these two csv files... be specific in telling me through java only Any help will be much appreciated
Java-Connection Pool - JDBC
Java-Connection Pool  How can I create a connection pool. My database is MS SQL server 2000(username-sa, pwd-admin) and my application server is Weblogic 8. Which is the best approach to create a connection pool? Kindly help

Ads