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-Servletinteconnecting 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
Advertisements
Two forms and One ServletTwo
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 FORMSJAVA 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
ModuleNotFoundError: No module named 'cms-forms'ModuleNotFoundError: No module named 'cms-
forms' Hi,
My Python... 'cms-
forms'
How to remove the ModuleNotFoundError: No module named 'cms-
forms' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'cms-forms'ModuleNotFoundError: No module named 'cms-
forms' Hi,
My Python... 'cms-
forms'
How to remove the ModuleNotFoundError: No module named 'cms-
forms' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'gnue-forms'ModuleNotFoundError: No module named 'gnue-
forms' Hi,
My Python... 'gnue-
forms'
How to remove the ModuleNotFoundError: No module named 'gnue-
forms' error?
Thanks
Hi,
In your python environment you
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
Maven Dependency forms >> 1.0.4You 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 >> 1.0.5You should include the dependency code given in this page to add Maven Dependency of jgoodies >>
forms version1.0.5 in your project