inteconnecting forms

Ads

 
 

Share on Google+Share on Google+

vijay sood
inteconnecting forms
1 Answer(s)      8 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

Ads









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
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
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
Version of jgoodies>forms dependency
List of Version of jgoodies>forms dependency
Version of swt>forms dependency
List of Version of swt>forms dependency
Version of com.jgoodies>forms dependency
List of Version of com.jgoodies>forms dependency
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
Version of cocoon>cocoon-forms dependency
List of Version of cocoon>cocoon-forms dependency
Version of com.intellij>forms_rt dependency
List of Version of com.intellij>forms_rt dependency
Version of com.jgoodies>jgoodies-forms dependency
List of Version of com.jgoodies>jgoodies-forms dependency
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
Maven Dependency forms >> 1.0.5
You should include the dependency code given in this page to add Maven Dependency of jgoodies >> forms version1.0.5 in your project
Maven Dependency forms >> 3.0m8
You should include the dependency code given in this page to add Maven Dependency of swt >> forms version3.0m8 in your project
Maven Dependency forms >> 1.0.7
You should include the dependency code given in this page to add Maven Dependency of com.jgoodies >> forms version1.0.7 in your project
Maven Dependency forms >> 1.1.0
You should include the dependency code given in this page to add Maven Dependency of com.jgoodies >> forms version1.1.0 in your project
Maven Dependency forms >> 1.2.0
You should include the dependency code given in this page to add Maven Dependency of com.jgoodies >> forms version1.2.0 in your project
Maven Dependency forms >> 1.2.1
You should include the dependency code given in this page to add Maven Dependency of com.jgoodies >> forms version1.2.1 in your project
Maven Dependency forms >> 1.0.4
You should include the dependency code given in this page to add Maven Dependency of jgoodies >> forms version1.0.4 in your project
Maven Dependency forms >> 3.0m7
You should include the dependency code given in this page to add Maven Dependency of swt >> forms version3.0m7 in your project
Maven Dependency forms >> 1.1-preview
You should include the dependency code given in this page to add Maven Dependency of com.jgoodies >> forms version1.1-preview in your project
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
Maven Dependency cocoon-forms >> 2.1.5.1
You should include the dependency code given in this page to add Maven Dependency of cocoon >> cocoon-forms version2.1.5.1 in your project
Maven Dependency cocoon-forms >> 2.1.6
You should include the dependency code given in this page to add Maven Dependency of cocoon >> cocoon-forms version2.1.6 in your project
Maven Dependency cocoon-forms >> 2.1.7
You should include the dependency code given in this page to add Maven Dependency of cocoon >> cocoon-forms version2.1.7 in your project
Maven Dependency cocoon-forms >> 2.1.8
You should include the dependency code given in this page to add Maven Dependency of cocoon >> cocoon-forms version2.1.8 in your project
Maven Dependency forms_rt >> 4.5.4
You should include the dependency code given in this page to add Maven Dependency of com.intellij >> forms_rt version4.5.4 in your project

Ads

 
Advertisement null

Ads