displaying data based on criteria from 2 tables having same type of data
Dear Experts,
First, thanks for replying my question regarding my servlet.
My mind was very confused then. I realise that I can't use a servlet to process search criteria without having a form.
I have recently read up about DAO pattern and I think it might be able to solve my problem. Correct me if I'm wrong. Some other forums told me to use Hibernate for my problem so I'm quite lost.
Hence, I hope the experts here can give me some sample code how to write my code.
Basically, I have 2 forms already. One for tutors and the other for parents.
So, now I need a servlet (or I do not need one? ...please advise) to process a search.
The search will have following features:-
1. it enables me to enter the ID of the parents.
2. based on the ID of parents I will know what is the type of tutors they are looking for - e.g. budget, type of tutors.
3. thereafter, there will be a button to allow me to display the tutors that match the parent's requirements.
OK. I look forward to your guidance. Many thanks.
View Answers
June 8, 2010 at 5:18 PM
Hi Friend,
You can use jsp or servlet or both. We have used jsp.
Try the following code:
1)enter.jsp:
<%@page import="java.sql.*"%>
<script>
function info(sub,qua){
window.open("info.jsp?sub="+sub+"&&qua="+qua,'mywindow','width=300, height=200,toolbar=no,resizable=yes,menubar=yes');
}
</script>
<form>
Enter ID:<input type="text" name="id"><input type="submit" value="Submit" style="background-color:#49743D;font-weight:bold;color:#ffffff;">
</form>
<%String id=request.getParameter("id");
if(id!=null){
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:
mysql://localhost:3306/mysql";, "root", "root");
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM parents where id='"+id+"'");
%>
<table border="1">
<tr><th>Subject</th><th>Qualification</th><th>Get Information</th></tr>
<%
while(rs.next()){
String sub=rs.getString("subjects");
String qua=rs.getString("qualification");
%>
<tr><td><%=rs.getString("subjects")%></td><td><%=rs.getString("qualification")%></td><td><input type=button value="Get" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick='info("<%=sub%>","<%=qua%>")'></td></tr>
<%
}
%>
</table>
<%
}
%>
2)info.jsp:
<%@page import="java.sql.*"%>
<%
String sub=request.getParameter("sub");
String qua=request.getParameter("qua");
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:
mysql://localhost:3306/mysql";, "root", "root");
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM memberparticulars WHERE subjects='"+sub+"' and degree='"+qua+"'");
%>
<center>
<table border="1">
<tr><th>Name</th><th>Contact</th><th>Subjects</th></tr>
<%
while(rs.next()){
%>
<tr><td><%=rs.getString("name")%></td><td><%=rs.getString("contact")%></td><td><%=rs.getString("subjects")%></td></tr>
<%
}
%>
</table>
</center>
We have created following database tables:
1)'parents'
CREATE TABLE `parents` (
`id` bigint(255) NOT NULL auto_increment,
`subjects` varchar(255) default NULL,
`qualification` varchar(255) default NULL,
PRIMARY KEY (`id`)
)
2'memberparticulars'
CREATE TABLE `memberparticulars` (
`id` bigint(255) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`contact` varchar(255) default NULL,
`subjects` varchar(255) default NULL,
`degree` varchar(255) default NULL,
PRIMARY KEY (`id`)
)
Hope that it will be helpful for you.
Thanks
Related Tutorials/Questions & Answers:
same data inserted 2 timessame data inserted
2 times thanks for reply,
i know the insert command. but
same data inserted
2 times.where is the problem i cannot understood
Advertisements
inserting same data to different tables in oracleinserting
same data to different
tables in oracle Hi there ...! i have to insert un,pwd, to three oracle
tables, like admin, user, stud, but i want pickup these table names
from a drop down list in html...is there any chance can
inserting same data to different tables in oracleinserting
same data to different
tables in oracle Hi there ...! i have to insert un,pwd, to three oracle
tables, like admin, user, stud, but i want pickup these table names
from a drop down list in html...is there any chance can
inserting same data to different tables in oracleinserting
same data to different
tables in oracle Hi there ...! i have to insert un,pwd, to three oracle
tables, like admin, user, stud, but i want pickup these table names
from a drop down list in html...is there any chance can
inserting same data to different tables in oracleinserting
same data to different
tables in oracle Hi there ...! i have to insert un,pwd, to three oracle
tables, like admin, user, stud, but i want pickup these table names
from a drop down list in html...is there any chance can
inserting same data to different tables in oracleinserting
same data to different
tables in oracle Hi there ...! i have to insert un,pwd, to three oracle
tables, like admin, user, stud, but i want pickup these table names
from a drop down list in html...is there any chance can
inserting same data to different tables in oracleinserting
same data to different
tables in oracle Hi there ...! i have to insert un,pwd, to three oracle
tables, like admin, user, stud, but i want pickup these table names
from a drop down list in html...is there any chance can
Displaying data from combobox on the web pageDisplaying data from combobox on the web page Sir, I have to make a project in which a
data from the database is to be displayed in combo box and depending on the choice made in combo box the
data pertaining to it
from Displaying data from combobox on the web pageDisplaying data from combobox on the web page Sir, I have to make a project in which a
data from the database is to be displayed in combo box and depending on the choice made in combo box the
data pertaining to it
from Displaying data from combobox on the web pageDisplaying data from combobox on the web page Sir, I have to make a project in which a
data from the database is to be displayed in combo box and depending on the choice made in combo box the
data pertaining to it
from Displaying data from combobox on the web pageDisplaying data from combobox on the web page Sir, I have to make a project in which a
data from the database is to be displayed in combo box and depending on the choice made in combo box the
data pertaining to it
from Displaying data from combobox on the web pageDisplaying data from combobox on the web page Sir, I have to make a project in which a
data from the database is to be displayed in combo box and depending on the choice made in combo box the
data pertaining to it
from Purge Data from Mysql tablesPurge
Data from Mysql tables Hi,
i have to write a mysql procedure to purge
data from tables.
but written procedure clear entire
tables data.
Please give me the solution for purging
data.
CREATE DEFINER=`root`@`localhost
same data inserted 2 times in databasesame data inserted
2 times in database pls help me,
i have table studentmaster(firstname,lastname,fathername,phone,address).
i am inserting
data into database
2 times the
data will be inserted.
forexample:
firstname
displaying datadisplaying data how to display
data from database on jsp using struts2
jsp programe for displaying data from databasejsp programe for
displaying data from database i am using JSP.i want..."')");
ResultSet rs = stmt.executeQuery( "SELECT *
FROM data");
String id.../WebSevices/19592-retriving-
data-
from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from databasejsp programe for
displaying data from database i am using JSP.i want..."')");
ResultSet rs = stmt.executeQuery( "SELECT *
FROM data");
String id.../WebSevices/19592-retriving-
data-
from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from databasejsp programe for
displaying data from database i am using JSP.i want..."')");
ResultSet rs = stmt.executeQuery( "SELECT *
FROM data");
String id.../WebSevices/19592-retriving-
data-
from-sql-server-using-jsp-code-and-placing-them
Data Conversion from int to another typeData conversion is the conversion of
data from one
type to another
type.
In this section we will learn about
data conversion
from int primitive
type to another
data type like String, boolean and char etc
Data Conversion from String to another typeData conversion is the conversion of
data from one
type to another
type.
In this section we will learn about
data conversion
from String primitive
type to another
data type like int, boolean and char etc
Data Conversion from float to another typeData conversion is the conversion of
data from one
type to another
type.
In this section we will learn about
data conversion
from float primitive
type to another
data type like String, boolean and char etc
Data Conversion from short to another typeData conversion is the conversion of
data from one
type to another
type.
In this section we will learn about
data conversion
from short primitive
type to another
data type like String, boolean and char etc
Data Conversion from byte to another typeData conversion is the conversion of
data from one
type to another
type.
In this section we will learn about
data conversion
from byte primitive
type to another
data type like String, boolean and char etc
Data Conversion from double to another typeData conversion is the conversion of
data from one
type to another
type.
In this section we will learn about
data conversion
from double primitive
type to another
data type like String, boolean and char etc
Data Conversion from long to another typeData conversion is the conversion of
data from one
type to another
type.
In this section we will learn about
data conversion
from long primitive
type to another
data type like String, boolean and char etc
displaying data from ms excel in form.displaying data from ms excel in form. Hi all,
I have a requirement as mentioned below:
Requirement: I have stored some
data in the ms excel... (for example). I need to display these
data in a form. along with the actual picture
sql query to get data from two tablessql query to get
data from two tables how can i get the
data from two different
tables?
Hi Friend,
Please visit the following link:ADS_TO_REPLACE_1
JOIN Query
Simple Query
ThanksADS_TO_REPLACE_2
Data fetch from multiple SQL tables - Hibernate that would use table classes to retrieve
data from 8 or 9
tables.
Any example of HQL fetching
data from multiple
tables would be a help.
I have tried...
Data fetch
from multiple SQL tables
I am in the process of writing
displaying data retrieved from a database in a jsp pagedisplaying data retrieved
from a database in a jsp page the page should display username, emailid, telephone in addition to tthe tagline however... sql = "select billid, customerid, billdate, status
from customerbills where
data typedata type which
data type is used to store video file in mysql databse
xml displaying a drives data.....xml
displaying a drives
data..... Hi all,
I need a solution for
displaying content of a drive(Ex: c , d , e ) in the browser using the XML...,
You can't access the your drive
data from browser. But you can create some
Get date data type from tableGET DATE
DATA TYPE FROM TABLE
In this example , we will get "Date"
data type from a table of "Mysql"
database and it also display...
data = rs.getString(
2);
System.out.println(name +"\t"+
data Is big data and data science same?Is big
data and
data science
same? Hi,
I am beginner in
Data...:
Is big
data and
data science
same?
Try to provide me good examples or tutorials links so that I can learn the
topic "Is big
data and
data science
same?"
Is Data Analyst same as data scientist?Is
Data Analyst
same as
data scientist? Hi,
I am beginner in
Data...:
Is
Data Analyst
same as
data scientist?
Try to provide me good examples or tutorials links so that I can learn the
topic "Is
Data Analyst
same as
data data typedata type what are the date types in the java and vb.net?
what is the difference between java and vb.net?
Hi Friend,
java
data types...
vb.net
data types are:
Byte
SByte
Short
UShort
Integer
UInteger
Long
ULong
Is data science and analytics same?Is
data science and analytics
same? Hi,
I am beginner in
Data...:
Is
data science and analytics
same?
Try to provide me good examples or tutorials links so that I can learn the
topic "Is
data science and analytics
same Data displaying with limited records in jspData displaying with limited records in jsp How to display table with limited 10 records , after clicking next button another 10 records
from database upto last record please help me
alter data typealter
data type alter
data type of subName column for subject table to varchar(40