displaying data based on criteria from 2 tables having same type of data

Ads

 
 

Share on Google+Share on Google+

Karen
displaying data based on criteria from 2 tables having same type of data
1 Answer(s)      6 years and 11 months ago
Posted in : Java Beginners
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.

Ads
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:

<[email protected] 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:

<[email protected] 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

Ads









Related Tutorials/Questions & Answers:
displaying data based on criteria from 2 tables having same type of data - Java Beginners
displaying data based on criteria from 2 tables having same type of data ... to process search criteria without having a form. I have recently read up about.... it enables me to enter the ID of the parents. 2. based on the ID of parents I will know
same data inserted 2 times
same 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 oracle
inserting 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 oracle
inserting 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 oracle
inserting 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 oracle
inserting 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 oracle
inserting 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 oracle
inserting 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
Purge Data from Mysql tables
Purge 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
displaying data
displaying data   how to display data from database on jsp using struts2
same data inserted 2 times in database
same 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 data from combobox on the web page
Displaying 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 page
Displaying 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 page
Displaying 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 page
Displaying 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 page
Displaying 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
jsp programe for displaying data from database
jsp 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 database
jsp 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 database
jsp 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
sql query to get data from two tables
sql query to get data from two tables  how can i get the data from two different tables?   Hi Friend, Please visit the following link: JOIN Query Simple Query Thanks
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 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
displaying data retrieved from a database in a jsp page
displaying 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 Conversion from long to another type
Data 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
Data Conversion from float to another type
Data 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 byte to another type
Data 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 int to another type
Data 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 type
Data 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 double to another type
Data 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 short to another type
Data 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 type
data type  which data type is used to store video file in mysql databse
Tutorials   
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017

Ads

 
Advertisement null

Ads