Results 1 to 2 of 2

Thread: how to get 'count rows' from table

  1. #1
    Join Date
    Oct 2003
    Posts
    1

    how to get 'count rows' from table

    hello,

    below is my work
    it is a jsp+HTML+sql server code
    it is very simple
    jux retrieve data from the table that i've built
    the code below:

    <%@ page import="javax.naming.*" %>
    <%@ page import="javax.sql.DataSource" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.util.Date" %>
    <%@ page import="java.text.DateFormat" %>
    <%@ page import="java.io.File" %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>newspage_forum_index</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <%
    try{
    Context initContext = new InitialContext();
    Context envContext = (Context)initContext.lookup("java:/comp/env");
    DataSource ds = (DataSource)envContext.lookup("jdbc/fsDS");


    if(ds != null){
    Connection con = ds.getConnection();
    if(con != null)
    {

    %>
    <b>Try Forum
    <%
    String sql = "SELECT * FROM User_Forum";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    while(rs.next())
    {
    %>
    <p>
    <br>Topic : <%= rs.getString("Topic")%>
    <br>Author : <%= rs.getString("Author")%>
    <br>Message : <%= rs.getString("Message")%>
    <br>Email : <%= rs.getString("Email")%>
    <br>own date : <%= DateFormat.getDateInstance().format(new Date()) %>
    <br>own time : <%= DateFormat.getTimeInstance().format(new Date()) %>
    <br>modify date : <%= DateFormat.getDateInstance().format(new Date(new File(application.getRealPath(request.getServletPat h())).lastModified())) %>
    <br>modify time : <%= DateFormat.getTimeInstance().format(new Date(new File(application.getRealPath(request.getServletPat h())).lastModified())) %>

    <%

    }
    }else{
    %>
    <b>Connection is null
    <%
    }
    }else{
    %>
    <b>Data Source is null
    <%
    }
    }catch(Exception e){
    e.printStackTrace();
    }
    %>
    </body>
    </html>



    now
    the problem is
    how can i get the table row using these code?
    for example,my table has 4 rows
    now i want the jsp or sql statement help me to display "4"

    can anyone out there help me?
    10s

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    select count(*) as MyCount from tablename

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •