Solved

count command in sql using jsp

Posted on 2004-04-08
11
1,180 Views
Last Modified: 2008-01-16
What is the format used for the count command using jsp.
This is what im using,

int cnt = stmt.execteQuery("SELECT count('"+id+"') FROM members ");

any suggestion of a good site that shows how to use mysql with jsp effectively.
0
Comment
Question by:Raftor
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10787116
ResultSet rs = stmt.execteQuery("SELECT count(id) FROM members ");

int count = rs.getInt(1);
0
 

Author Comment

by:Raftor
ID: 10787238
That didnt work either if gave this error,

The server encountered an internal error () that prevented it from fulfilling this request.

Do you know of any sites that have sql and jsp tutorials?
0
 
LVL 1

Expert Comment

by:gagaliya
ID: 10787288
ResultSet rs = stmt.execteQuery("SELECT count \("+id+"\) FROM members ");
int count = rs.getInt(1);

if you want to count all rows in a table just do

ResultSet rs = stmt.execteQuery("SELECT count \(*\) FROM members");
int count = rs.getInt(1);
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Expert Comment

by:gagaliya
ID: 10787305
jsp uses the exact same codes as java to do sql, as a matter of fact it is java.

so just search tutorial jdbc on www.google.com 
for sql tutorial go here: http://www.w3schools.com/sql/default.asp
0
 

Author Comment

by:Raftor
ID: 10787494
no none of those worked either.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10787517
ooops my fault again...

ResultSet rs = stmt.execteQuery("SELECT count(id) FROM members ");
if(rs.next())
int count = rs.getInt(1);
0
 

Author Comment

by:Raftor
ID: 10787601
 This is the code i am using. It would only work if i put it in braces. But the problem is now is that i cannot access count outside the braces.              

                Statement st = con.createStatement();
            ResultSet res = st.executeQuery("SELECT count(id) FROM members ");
            if(res.next()){
                  String count = res.getString(1);
            }
            out.println("the count: " + count);

This is the error i get when i try to access count outside the braces.

symbol  : variable count
location: class org.apache.jsp.admin_home_page_jsp
            out.println("the count: " + count);
                                                      ^
0
 

Author Comment

by:Raftor
ID: 10787621
sorry i posted the wrong code i was actually using
          int count = res.getInt(1);
0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 50 total points
ID: 10787633

                Statement st = con.createStatement();
int count=0;
          ResultSet res = st.executeQuery("SELECT count(id) FROM members ");
          if(res.next()){
                count = res.getInt(1);
          }
          out.println("the count: " + count);
0
 

Author Comment

by:Raftor
ID: 10787675
Thats great thanks
0
 

Expert Comment

by:raship
ID: 10847904
I have written a javascript. Its a form. I need to somehow connect to my sql database and then add all the information into sql tables. I would really appreciate if someone can help me with this part. I am writing the code of the form here just so you have an idea of what information my sql tables need to store. If you just copy paste this file as *.html it should work just to save u some time.Thank you very much for your time.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>The Website made by Raship Shah</TITLE>
<STYLE>.c {
      FONT-SIZE: 12px; COLOR: #0000ff; FONT-FAMILY: Arial,Helvetica
}
.d {
      FONT-SIZE: 12px; COLOR: #000099; FONT-FAMILY: Arial,Helvetica
}
.r {
      FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Arial,Helvetica
}
.info {
      FONT-SIZE: 14px; COLOR: #000000; FONT-FAMILY: Arial,Helvetica
}
.nav {
      FONT-WEIGHT: bold; FONT-SIZE: 15px; COLOR: #ffffb0; FONT-FAMILY: Arial,Helvetica
}
.footer {
      FONT-SIZE: 10px; COLOR: #000099; FONT-FAMILY: Arial,Helvetica
}
.smtxt {
      FONT-SIZE: 10px; COLOR: #000000; FONT-FAMILY: Arial,Helvetica
}
.mdtxt {
      FONT-SIZE: 11px; COLOR: #000000; FONT-FAMILY: Arial,Helvetica
}
.menubar {
      FONT-SIZE: 11px; COLOR: #8080d0; FONT-FAMILY: Arial,Helvetica
}
.phone {
      FONT-WEIGHT: bold; FONT-SIZE: 16px; COLOR: #ffffff
}
.s {
      FONT-SIZE: 13px; COLOR: #000000; FONT-FAMILY: Geneva,Arial,Helvetica
}
.form {
      FONT-SIZE: 11px; COLOR: #000000; FONT-FAMILY: Geneva,Arial,Helvetica
}
</STYLE>

<SCRIPT language=JavaScript1.1 src="FormChek.js">
</SCRIPT>

<SCRIPT>
function validateUSPersonalInfo(form)
{   return (
            checkString(form.elements["last_name"],sUSLastName) &&
            checkString(form.elements["first_name"],sUSFirstName) &&
          checkString(form.elements["contact_number"],'Contact Number') &&
      checkString(form.elements["diners"],'Number of Diners') &&
        checkEmail(form.elements["email"], false)
    )
}
</SCRIPT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD><BR>
      <FORM action=procpage.html method=post><INPUT type=hidden value=775 name=r>
      <CENTER>
      <TABLE cellPadding=1 width=500 bgColor=#f0f0f0 border=0>
        <TBODY>
        <TR>
          <TD class=form><p>First Name</p>          </TD>
          <TD class=form><INPUT size=30 name=first_name></TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Last Name</p></TD>
          <TD class=form><INPUT size=30 name=last_name></TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Telephone Number</p></TD>
          <TD class=form><INPUT name=contact_number></TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Number of Diners:</p></TD>
          <TD class=form><INPUT size=5 name=diners></TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Preferred Reservation Date:</p></TD>
          <TD class=form><SELECT name=month> <OPTION selected
              val="Select month">Select month</OPTION> <OPTION
              val="March">March</OPTION> <OPTION val="April">April</OPTION>
              <OPTION val="May">May</OPTION></SELECT> <SELECT name=date> <OPTION
              val="1">1</OPTION> <OPTION val="2">2</OPTION> <OPTION selected
              val="3">3</OPTION> <OPTION val="4">4</OPTION> <OPTION
              val="5">5</OPTION> <OPTION val="6">6</OPTION> <OPTION
              val="7">7</OPTION> <OPTION val="8">8</OPTION> <OPTION
              val="9">9</OPTION> <OPTION val="10">10</OPTION> <OPTION
              val="11">11</OPTION> <OPTION val="12">12</OPTION> <OPTION
              val="13">13</OPTION> <OPTION val="14">14</OPTION> <OPTION
              val="15">15</OPTION> <OPTION val="16">16</OPTION> <OPTION
              val="17">17</OPTION> <OPTION val="18">18</OPTION> <OPTION
              val="19">19</OPTION> <OPTION val="20">20</OPTION> <OPTION
              val="21">21</OPTION> <OPTION val="22">22</OPTION> <OPTION
              val="23">23</OPTION> <OPTION val="24">24</OPTION> <OPTION
              val="25">25</OPTION> <OPTION val="26">26</OPTION> <OPTION
              val="27">27</OPTION> <OPTION val="28">28</OPTION> <OPTION
              val="29">29</OPTION> <OPTION val="30">30</OPTION> <OPTION
              val="31">31</OPTION></SELECT> <SELECT name=year> <OPTION selected
              val="2004">2004</OPTION></SELECT> &nbsp; <a href="calender.html">(Calendar)</a></TD>
        </TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Approximate 1st Choice Reservation Time</p></TD>
          <TD class=form><SELECT name=firsttime><OPTION>1:00</OPTION>
              <OPTION>1:30</OPTION> <OPTION>2:00</OPTION> <OPTION>2:30</OPTION>
              <OPTION>3:00</OPTION> <OPTION>3:30</OPTION> <OPTION>4:00</OPTION>
              <OPTION>4:30</OPTION> <OPTION>5:00</OPTION> <OPTION>5:30</OPTION>
              <OPTION>6:00</OPTION> <OPTION>6:30</OPTION> <OPTION
              selected>7:00</OPTION> <OPTION>7:30</OPTION> <OPTION>8:00</OPTION>
              <OPTION>8:30</OPTION> <OPTION>9:00</OPTION> <OPTION>9:30</OPTION>
              <OPTION>10:00</OPTION> <OPTION>10:30</OPTION>
              <OPTION>11:00</OPTION> <OPTION>11:30</OPTION>
              <OPTION>12:00</OPTION> <OPTION>12:30</OPTION></SELECT> <INPUT
            type=radio value=AM name=firstampm>AM <INPUT type=radio CHECKED
            value=PM name=firstampm>PM </TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Approximate 2nd Choice Reservation Time</p></TD>
          <TD class=form><SELECT name=secondtime><OPTION>1:00</OPTION>
              <OPTION>1:30</OPTION> <OPTION>2:00</OPTION> <OPTION>2:30</OPTION>
              <OPTION>3:00</OPTION> <OPTION>3:30</OPTION> <OPTION>4:00</OPTION>
              <OPTION>4:30</OPTION> <OPTION>5:00</OPTION> <OPTION>5:30</OPTION>
              <OPTION>6:00</OPTION> <OPTION>6:30</OPTION> <OPTION>7:00</OPTION>
              <OPTION>7:30</OPTION> <OPTION selected>8:00</OPTION>
              <OPTION>8:30</OPTION> <OPTION>9:00</OPTION> <OPTION>9:30</OPTION>
              <OPTION>10:00</OPTION> <OPTION>10:30</OPTION>
              <OPTION>11:00</OPTION> <OPTION>11:30</OPTION>
              <OPTION>12:00</OPTION> <OPTION>12:30</OPTION></SELECT> <INPUT
            type=radio value=AM name=secondampm>AM <INPUT type=radio CHECKED
            value=PM name=secondampm>PM </TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Seating preference:</p></TD>
          <TD class=form><INPUT type=radio CHECKED value=N
            name=smoking>Non-Smoking <INPUT type=radio value=Y
            name=smoking>Smoking <INPUT type=radio value=E name=smoking>Either
          </TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Confirm via:</p></TD>
          <TD class=form><p>
              <INPUT type=radio CHECKED value=E
            name=confirm_method>
              E-mail
              </p>
            <p>
    <INPUT type=radio value=P
            name=confirm_method>
    Phone/voicemail    </p>
            <p>
    <INPUT type=radio value=F
            name=confirm_method>
    Fax </p></TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>E-mail:</p></TD>
          <TD class=form><INPUT size=25 name=email></TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Business telephone (w/area code):</p></TD>
          <TD class=form><INPUT name=business_number></TD></TR>
        <TR>
          <TD class=form><p>&nbsp;</p>
          <p>Fax number:</p></TD>
          <TD class=form><INPUT name=fax_number></TD></TR>
          <p><BR>
            <INPUT name=reserve type=submit onclick="return validateUSPersonalInfo(this.form);" value="Submit Reservation Now">
      </BR>
        </p>
   
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Apache server configuration 7 85
constuctor calling other constructor 2 76
stateless EJB with glassfish 2 73
if statement not resolving in my code 5 52
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Read about the importance of offline branding in the digital age.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question