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



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

Have Programming Question? Ask it here!
 
 
 


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



Advertisement
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...; <HEAD> <TITLE>multiple catch in single jsp program<
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
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
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
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
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
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
Java single threaded model
Java single threaded model  How single threaded model works after implementation in class, basically architecture point of view
Java jdbc connection
Java jdbc connection  Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection
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.
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
java connection leak
java connection leak  How to check the connection leak in Java
connection
connection   how to make multiple database connection using jdbc
connection with MySQL to java.
connection with MySQL to java.   how to connect MySQL database with jsp
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
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 DATABASE CONNECTION WITH JTABLE
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
Java Jdbc connection
Java Jdbc connection  What are the steps involved for making a connection with a database or how do you connect to a database
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
Java FTP Connection
Java FTP Connection  I am learning to develop a program in Java. As a learning process I want to make a connection to the FTP server just to check if it works? How to make Java FTP Connection to FTP server hosted in my network
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
Java-Connection Pool - JDBC
Java-Connection Pool  How can I create a connection pool. My database... is Weblogic 8. Which is the best approach to create a connection pool? ...{ public static void main(String[] args){ Connection con = null; String url
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
Java Connection to Oracle database
Java Connection to Oracle database  HI I am ubable to connnect jdbc to Oracle database.i had gone to control panel >>Administrative... type properly and the Test Connection failed.So Kindly tell me what to type in TNS
Connection pooling - Java Beginners
Connection pooling  Respected Sir/Madam, I am Ragavendran.R.. I got your link which u have sent for implementing connection pooling... for implementing connection pooling for the below mentioned: Ahead.jsp: Client
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
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
java database connection - JDBC
java database connection  sir i want to join my project with MS access database. i am making my project in netbeans.please tell me the coding to do...{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connect
Connection pooling - Java Beginners
Connection pooling  Respected Sir/Madam, I have developed an application and I am now trying to implement the same through connection pooling. I have totally 6 files in that application viz Login.jsp, check.jsp, Ahead.jsp
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
Java Jdbc connection
Java Jdbc connection  What is the use of Class.forName
Advertisements
 

 

 

DMCA.com