By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 820 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

please help me

P: 83
Hi
i have the html page to connect the jsp.

<html>
<body>
<form id="form1" name="form1" method="post" action="http://localhost:8080/admin/Example.jsp">
<textarea name="textarea" cols="" rows=""></textarea>
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
in this how to match the text field with jsp page. for example in text field i enter the table select option the corresponding table will be displayed.

In jsp i wrote the code that will diplay the content of the particular table. but my problem is how to match it.
the jsp code is

<%@ page import="java.sql.*" %>
<%
//String connectionURL = ("jdbc:mysql://localhost:3306/test";user="root";password="icc");
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>

<html><body>

<%
Class.forName("com.mysql.jdbc.Driver").newInstance ();
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "index");
statement = connection.createStatement();
rs = statement.executeQuery("select * from profit");
while (rs.next()) {
out.println(rs.getString("name")+"<br>");
out.println(rs.getString("id")+"<br>");
out.println("inserted" +"<br>");

}

rs.close();
%>

in the html text filed i enter select * from profit the above code is executed otherwise not excuted.
please give me your advice
Thanks in advance

Sang.
Oct 5 '06 #1
Share this Question
Share on Google+
5 Replies


10K+
P: 13,264
Hi
i have the html page to connect the jsp.

<html>
<body>
<form id="form1" name="form1" method="post" action="http://localhost:8080/admin/Example.jsp">
<textarea name="textarea" cols="" rows=""></textarea>
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
in this how to match the text field with jsp page. for example in text field i enter the table select option the corresponding table will be displayed.

In jsp i wrote the code that will diplay the content of the particular table. but my problem is how to match it.
the jsp code is

<%@ page import="java.sql.*" %>
<%
//String connectionURL = ("jdbc:mysql://localhost:3306/test";user="root";password="icc");
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>

<html><body>

<%
Class.forName("com.mysql.jdbc.Driver").newInstance ();
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "index");
statement = connection.createStatement();
rs = statement.executeQuery("select * from profit");
while (rs.next()) {
out.println(rs.getString("name")+"<br>");
out.println(rs.getString("id")+"<br>");
out.println("inserted" +"<br>");

}

rs.close();
%>

in the html text filed i enter select * from profit the above code is executed otherwise not excuted.
please give me your advice
Thanks in advance

Sang.
In the jsp do
Expand|Select|Wrap|Line Numbers
  1. String theSql = request.getParameter("textarea");
the use theSql to conduct the query
Oct 5 '06 #2

P: 83
Thankyou for your reply

the above code is executed with my jsp program. I have another doubt in the same.That is my jsp program is execute for one table only,but i want execute all the tables in my database with same method.

That is through the html. in the text field(html) i will enter the any of the table in mydatabase that is excuted in the output.

please give your advice,
Thanks
Sang.
Oct 5 '06 #3

10K+
P: 13,264
Thankyou for your reply

the above code is executed with my jsp program. I have another doubt in the same.That is my jsp program is execute for one table only,but i want execute all the tables in my database with same method.

That is through the html. in the text field(html) i will enter the any of the table in mydatabase that is excuted in the output.

please give your advice,
Thanks
Sang.
Now that the sql is being input in a form, any querry for any table in the database can be input as long as it is valid sql.
Oct 5 '06 #4

P: 83
Thankyou very much for your reply.

I am not understand that sql is being input in the form. pls give in detail.

the path of sql is given to the form (ie installation path or not) i am totaly confused pls give in detail

Thankyou
Sang
Oct 6 '06 #5

10K+
P: 13,264
Thankyou very much for your reply.

I am not understand that sql is being input in the form. pls give in detail.

the path of sql is given to the form (ie installation path or not) i am totaly confused pls give in detail

Thankyou
Sang
Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.sql.*" %>
  2. <%
  3. //String connectionURL = ("jdbc:mysql://localhost:3306/test";user="root";password="icc");
  4. Connection connection = null;
  5. Statement statement = null;
  6. ResultSet rs = null;
  7. %>
  8.  
  9. <html><body>
  10.  
  11. <%
  12. String theSql = request.getParameter("textarea");//Get the sql from the form
  13. Class.forName("com.mysql.jdbc.Driver").newInstance();
  14. connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "index");
  15. statement = connection.createStatement();
  16. rs = statement.executeQuery(theSql);//******This is the beautiful part*****
  17. while (rs.next()) {
  18. out.println(rs.getString("name")+"<br>");
  19. out.println(rs.getString("id")+"<br>");
  20. out.println("inserted" +"<br>");
  21.  
  22. }
  23.  
  24. rs.close();
  25. %>
If you write valid sql statements in the form they
will be executed in the jsp as you input them.
The statements are coming from the user and not hardcoded into the program.
If you want to connect to anotherTable you simply type "select * from ANOTHERTABLE" in the textarea
an the jsp will get this and put in the variable theSql.
This will then be used to perform the database querry or update
Oct 6 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.