please help me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sang
    New Member
    • Sep 2006
    • 83

    please help me

    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.sq l.*" %>
    <%
    //String connectionURL = ("jdbc:mysql ://localhost:3306/test";user="roo t";password="ic c");
    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    %>

    <html><body>

    <%
    Class.forName(" com.mysql.jdbc. Driver").newIns tance();
    connection = DriverManager.g etConnection("j dbc:mysql://localhost:3306/test", "root", "index");
    statement = connection.crea teStatement();
    rs = statement.execu teQuery("select * from profit");
    while (rs.next()) {
    out.println(rs. getString("name ")+"<br>");
    out.println(rs. getString("id") +"<br>");
    out.println("in serted" +"<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.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by sang
    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.sq l.*" %>
    <%
    //String connectionURL = ("jdbc:mysql ://localhost:3306/test";user="roo t";password="ic c");
    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    %>

    <html><body>

    <%
    Class.forName(" com.mysql.jdbc. Driver").newIns tance();
    connection = DriverManager.g etConnection("j dbc:mysql://localhost:3306/test", "root", "index");
    statement = connection.crea teStatement();
    rs = statement.execu teQuery("select * from profit");
    while (rs.next()) {
    out.println(rs. getString("name ")+"<br>");
    out.println(rs. getString("id") +"<br>");
    out.println("in serted" +"<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
    Code:
    String theSql = request.getParameter("textarea");
    the use theSql to conduct the query

    Comment

    • sang
      New Member
      • Sep 2006
      • 83

      #3
      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.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by sang
        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.

        Comment

        • sang
          New Member
          • Sep 2006
          • 83

          #5
          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

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by sang
            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
            Code:
            <%@ 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>
            
            <%
            String theSql = request.getParameter("textarea");//Get the sql from the form
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "index");
            statement = connection.createStatement();
            rs = statement.executeQuery(theSql);//******This is the beautiful part*****
            while (rs.next()) {
            out.println(rs.getString("name")+"<br>");
            out.println(rs.getString("id")+"<br>");
            out.println("inserted" +"<br>");
            
            }
            
            rs.close();
            %>
            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

            Comment

            Working...