Help insert SQL query in jsp page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bylum
    New Member
    • Mar 2007
    • 15

    #1

    Help insert SQL query in jsp page

    Kindly please anyone here helps me how to check in my program,

    i want to insert this SQL query to jsp file:

    SELECT COUNT(id) new
    FROM annaudio
    WHERE id NOT IN (
    SELECT annaudio_id FROM annread WHERE annuser_id=1
    )


    and this is my jsp file's script:
    <%
    Class.forName ("org.gjt.mm.my sql.Driver");
    Connection connection = DriverManager.g etConnection("j dbc:mysql://localhost:3306/ann?user=root") ;
    Statement statement = connection.crea teStatement();

    ResultSet rs = statement.execu teQuery("SELECT COUNT(id) FROM annaudio WHERE id NOT IN(SELECT annaudio_id FROM annread WHERE annuser_id=" + "iduser)");

    out.println(rs) ;
    %>

    My problem is how to display my "ResultSet" ??
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    I have moved this thread to the Java forum, hopefully they will have some knowledge on the subject.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Did u see the SUN API Documentation of ResultSet interface?
      If u did then there would be no problem.
      Best of luck.

      Kind regards,
      Dmjpro.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by bylum
        Kindly please anyone here helps me how to check in my program,

        i want to insert this SQL query to jsp file:

        SELECT COUNT(id) new
        FROM annaudio
        WHERE id NOT IN (
        SELECT annaudio_id FROM annread WHERE annuser_id=1
        )


        and this is my jsp file's script:
        <%
        Class.forName ("org.gjt.mm.my sql.Driver");
        Connection connection = DriverManager.g etConnection("j dbc:mysql://localhost:3306/ann?user=root") ;
        Statement statement = connection.crea teStatement();

        ResultSet rs = statement.execu teQuery("SELECT COUNT(id) FROM annaudio WHERE id NOT IN(SELECT annaudio_id FROM annread WHERE annuser_id=" + "iduser)");

        out.println(rs) ;
        %>

        My problem is how to display my "ResultSet" ??
        Read sun's jdbc tutorial and see how to use resultsets. You probably won't take long to grasp it because it really is very simple.

        Comment

        • tmerkaj
          New Member
          • Jun 2007
          • 6

          #5
          Originally posted by r035198x
          Read sun's jdbc tutorial and see how to use resultsets. You probably won't take long to grasp it because it really is very simple.
          SELECT COUNT(id) new
          FROM annaudio
          WHERE id NOT IN (
          SELECT annaudio_id FROM annread WHERE annuser_id=1
          )


          and this is my jsp file's script:
          <%
          Class.forName ("org.gjt.mm.my sql.Driver");
          Connection connection = DriverManager.g etConnection("j dbc:mysql://localhost:3306/ann?user=root") ;
          Statement statement = connection.crea teStatement();

          ResultSet rs = statement.execu teQuery("SELECT COUNT(id) FROM annaudio WHERE id NOT IN(SELECT annaudio_id FROM annread WHERE annuser_id=" + "iduser)");

          out.println(rs) ;
          %>

          My problem is how to display my "ResultSet" ??


          Integer retval = getInteger(rs, 1);

          out.println( retval);

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by tmerkaj
            SELECT COUNT(id) new
            FROM annaudio
            WHERE id NOT IN (
            SELECT annaudio_id FROM annread WHERE annuser_id=1
            )


            and this is my jsp file's script:
            <%
            Class.forName ("org.gjt.mm.my sql.Driver");
            Connection connection = DriverManager.g etConnection("j dbc:mysql://localhost:3306/ann?user=root") ;
            Statement statement = connection.crea teStatement();

            ResultSet rs = statement.execu teQuery("SELECT COUNT(id) FROM annaudio WHERE id NOT IN(SELECT annaudio_id FROM annread WHERE annuser_id=" + "iduser)");

            out.println(rs) ;
            %>

            My problem is how to display my "ResultSet" ??


            Integer retval = getInteger(rs, 1);

            out.println( retval);
            If you wont go through the tutorial then at least take time to read the resultset specs.

            Comment

            • praveen2gupta
              New Member
              • May 2007
              • 200

              #7
              Originally posted by bylum
              Kindly please anyone here helps me how to check in my program,

              i want to insert this SQL query to jsp file:

              SELECT COUNT(id) new
              FROM annaudio
              WHERE id NOT IN (
              SELECT annaudio_id FROM annread WHERE annuser_id=1
              )


              and this is my jsp file's script:
              <%
              Class.forName ("org.gjt.mm.my sql.Driver");
              Connection connection = DriverManager.g etConnection("j dbc:mysql://localhost:3306/ann?user=root") ;
              Statement statement = connection.crea teStatement();

              ResultSet rs = statement.execu teQuery("SELECT COUNT(id) FROM annaudio WHERE id NOT IN(SELECT annaudio_id FROM annread WHERE annuser_id=" + "iduser)");

              out.println(rs) ;
              %>

              My problem is how to display my "ResultSet" ??

              execution of the above query will fetch only one record in the resultset. To print
              the value of the resultset you should use request.getPara meter("count(id )") will be displaying the output on the page.

              Comment

              Working...