vijay sood
inteconnecting forms
1 Answer(s)      7 years ago
Posted in : JSP-Servlet

Ads

View Answers

April 2, 2009 at 3:40 PM


Hi friend,

Following code will be helpful for you.

step1) Create a form in jsp page to enter table name.

<html>
<form name="form" action="retrieveData.jsp" method="post">
<table>
<tr><td>Enter table name:</td><td><input type="text" id="name" name="name"></td>
<tr><td><input type="submit" value="Submit"></td></tr>
</form>
</html>

step2) Now to retrieve the data of entered table name,create another jsp page.

<%@ page import="java.sql.*"%>
<%@ page import="java.io.*" %>
<html>
<head>
<title>database connectivity</title>
</head>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
Statement stmt=con.createStatement();
String table=request.getParameter("name");
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("Table Name= "+tableName);
out.println("<br>");
String strquery = "select * from "+tableName;
rs=stmt.executeQuery(strquery);
ResultSetMetaData md=rs.getMetaData();
int col= md.getColumnCount();
for (int i=0; i<col; i++) {
out.println(md.getColumnName(i+1));
}
out.println("<br>");
while(rs.next()){
for (int i=0; i<col; i++) {
out.println(rs.getString(i+1)+"\t");
}
out.println("<br>");
}
}
}
if(table.equals("")){
out.println("Enter table");
}
else if(!table.equals(tableName)) {
out.println("Table does not exist");
}
con.close();
}
catch(SQLException e) {
out.println("exception occured" +e);
}
%>
</body>
</html>

Thanks









Related Tutorials/Questions & Answers:
inteconnecting forms - JSP-Servlet
inteconnecting forms  hi, i have several tables in mysql database. i am creating some forms using jsp. i want to enter the name of the table and to get the table specified in the entry box to be displayed in the output
use forms.
use forms.  How do I use forms
Advertisements
tables to structure forms
tables to structure forms  How can I use tables to structure forms
tables to structure forms
tables to structure forms  How can I use tables to structure forms
use tables to structure forms
use tables to structure forms  How can I use tables to structure forms
use tables to structure forms
use tables to structure forms  How can I use tables to structure forms
Two forms and One Servlet
Two forms and One Servlet  Dear Sir, I have 2 forms in one page and one submit button into second form which submits data to one servlet. If I do... get both forms textbox value. Thanks in advance
JAVA BEAN WITH ORACLE FORMS
JAVA BEAN WITH ORACLE FORMS  Hi..I am doing my final year Project.. I need the ste-by-step procedure to integrate a bean with oracle forms? Please help me
What are different normalization forms?
What are different normalization forms?  What are different normalization forms?   Hi, 1NF: Eliminate Repeating Groups- Make a separate table for each set of related attributes, and give each table a primary key. Each
Date forms
Date forms       In this section we are demonstrating the retrieval of date from the Date object in various forms. In the following code segment we are performing
Multiple forms in JSP - JSP-Servlet
Multiple forms in JSP   Hi, I want to place multiple submit buttons in jsp pages ! and the multiple buttons will perform multiple actions based on the click of those buttons !   function
Two forms submission to one Action Class in Struts2.0
Two forms submission to one Action Class in Struts2.0  Hi, I have two forms.I want to submit two forms with only one submit button to the same action, same method. How can i get this. Please reply me
JSP WITH MULTIPLE FORMS
JSP WITH MULTIPLE FORMS       In  this example, you will learn how to make multiple forms in single jsp page. Most of the times people need to use multiple forms
Hide show HTML forms using javascript
Hide show HTML forms using javascript  How to hide a HTML form in my application using JavaScript?   HTML Code to create checkbox <...;div id="yourDiv"> ...other forms... </div> JavaScript function to hide
HTML Forms and PHP
Here we would integrate the HTML forms and PHP by creating HTML forms to collect the user input turning that input into variables, and then doing various...;YourName." This is what ties together forms and variables - each form field can
Print Only Forms Contents - Java Beginners
Print Only Forms Contents  Hello Sir I Have Created Simple Registration Form with Database Connectivity, Now I Want To Print Registration form Contents ,How I can Do that, plz Help Me  Hi Friend, Please go through
fill out forms on web pages - JDBC
fill out forms on web pages    I want to fill out forms on web pages, it's is very important to my project. For example there is a web-site www.blauh...com , in which there wil be a form , what i hav to do is to fill that form
jsf forms - Java Server Faces Questions
jsf forms  Hi, I have some queries in jsf forms please solve it. 1.how to set the height of a table 2. how to set the image at right side. 3.how to set a table in center. 4.i need one table and one image at one row tell me
Multiple Forms in JSP
Multiple Forms in JSP          The form tag creates a form for user input. A form can contain checkboxes, textfields, radio- buttons and many more. Forms are used
online voting systems with 10 forms and 3 pages calculations
online voting systems with 10 forms and 3 pages calculations  kindly send me the online voting system and online inventory management systems used by java or html, with 10 forms and 3 validation pages, with form designing
How to use Bean Area in Oracle Forms 9i with Sample code ?
How to use Bean Area in Oracle Forms 9i with Sample code ?  Hi friend.I posted a query,but I didn't get the answer for it.Help me to resolve including a bean area in oracle forms 9i and using it in forms.Thanks in advance.Help me
PHP HTML forms and Post Method Code
PHP HTML forms and Post Method Code PHP html function With the given PHP HTML Code one can retrieve the form data and display the input on same page. PHP... to create html forms and display data using PHP Post Method in PHP
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
The Normal Forms
The Normal Forms       The Normal Forms The database community sets the few rules or guidelines for database normalization. These rules are called as normal forms

Ads

Advertisement