Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


hendra
count in java
1 Answer(s)      5 years and 3 months ago
Posted in : Java Beginners



Advertisement
View Answers

May 27, 2009 at 3:35 PM


Hi Friend,

Try the following code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class Form extends JFrame
{
JButton ADD;
JPanel panel;
JLabel label1;
final JTextField text1;
Form()
{
label1 = new JLabel();
label1.setText("Gender:");
text1 = new JTextField(20);

ADD=new JButton("Count");
panel=new JPanel(new GridLayout(2,2));
panel.add(label1);
panel.add(text1);

panel.add(ADD);

add(panel,BorderLayout.CENTER);
setTitle("FORM");

ADD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();

Connection con = null;
String url = "jdbc:mysql://192.168.10.112:3306/";;
String db = "mydata";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
String i="";

Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("SELECT count(id_sales) from userlist where gender='"+value1+"'");
while(rs.next()){
i=rs.getString("count(id_sales)");
System.out.println(i);
JOptionPane.showMessageDialog(null,"Count is: "+i);
}

st.close();

con.close();
}
catch(Exception e){
System.out.println(e);
}
}
});
}
}
class RetrieveCount
{
public static void main(String arg[])
{
try
{
Form frame=new Form();
frame.setSize(300,100);
frame.setVisible(true);
}
catch(Exception e)
{}
}
}
Thanks


Related Tutorials/Questions & Answers:
count in java - Java Beginners
, count of frmale is 20. what's code in java to select count from database where...count in java  Hello javamania.... i want to ask something like... is 20. i have JFrame Form(jTextField,jLabel,jButton), i want to get count
Count the character in java
Count the character in java  Write a java program to count....   Count characters by implementing thread import java.util.*; class CountCharacters { public static void count(final String str){ Runnable
Advertisements
Ask java count
Ask java count  Good morning, I have a case where there are tables... | Java 1 | 10 | | b002 | beginner java | 5 | | b003 | advanced java book | 26 | | b004 | MySQL 1
letter count problem - Java Beginners
letter count problem  i have a problem in my java coding to count two characters of a string. eg to count the letter "ou" in the string "How do you feel today?". The answer should be 5. but i still have error compiling
count asterisk in a grid - Java Beginners
count asterisk in a grid  I need to write a program that uses a recursive method to count the number of asterisk in a square grid
Java program to generate the total count
Java program to generate the total count  I need a java program which would take a text file as an input and scans through it to generate the output. For Ex. : If the text file contains the following information: There is/are 3
Count characters from text file in Java
is a java code that count the occurrence of each character from text file. import...Count characters from text file in Java  At the "Count chracters fro mtext file in Java". I tried to run the code, but the error at the line have
Jsp count and java bean - JSP-Servlet
Jsp count and java bean  Please am on a project and i want to create a countdown timer that will have this format HH:MM:SS. Am working with jsp and java beans please somebody help.  Hi Friend, Try the following
count statement that saves results on a variable in a java bean
count statement that saves results on a variable in a java bean  ... = ""; ResultSet nu = null; SQLStr = "SELECT COUNT(*) AS COS FROM dev.history WHERE previous like 1; "; SQLStr = "SELECT COUNT(PREVIOUS
count statement that saves results on a variable in a java bean
count statement that saves results on a variable in a java bean  ... = ""; ResultSet nu = null; SQLStr = "SELECT COUNT(*) AS COS FROM dev.history WHERE previous like 1; "; SQLStr = "SELECT COUNT(PREVIOUS
how to count words in string using java
how to count words in string using java  how to count words in string...: "); String st=input.nextLine(); int count=0...()){ String token=stk.nextToken(); count
Count number of occurences and print names alphabetically in Java
Count number of occurences and print names alphabetically in Java  I... for the printCount() method for the code to count the number of occurences of each...]+" "; } str = str.toLowerCase(); int count = -1
Java count vowels
Java count vowels In this section you will learn how to count the number... and then you will get the number of vowels count. Description of code : In this code... will read the string once you enter the string. Then we have taken a count
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Java: Example - Count occurences
Java: Example - Count occurences Problem: Count the number of times one string is found in another. //-------------------------------------------- count() int count(String base, String searchFor) { int len
Java count files in a directory
Java count files in a directory In this section, you will learn how to count... directory. But we have to count the number of files so we have initialized... main(String[] args) { File f = new File("C:/Text"); int count = 0
Java Count Vowels
Java Count Vowels       In this program you will learn how to count vowels in a String. Here you... a variable- count = 0. Now, we have applied a loop here which will go up
Java file line count
Java file line count In the section, you will learn how to count the number of lines from the given file. Description of code: Java has provide various... main(String[] args) throws Exception { int count = 0; File f = new File("C
Count Active Thread in JAVA
Count Active Thread in JAVA In this tutorial, we are using activeCount() method of thread to count the current active threads. Thread activeCount() : Thread class provides you to check the current active thread by providing
Java Word Count - Word Count Example in Java
Java Word Count - Word Count Example in Java  ... to count the number of lines, number of words and number of characters... some strings and program will count the number of characters and number of words
count occourance no of time no between 0 to 9 given by user in java
count occourance no of time no between 0 to 9 given by user in java  import java.io.*; class count_no { public static void main(String args...); }catch(Exception e){} } }   Here is a java
Count characters from text file in Java
Count characters from text file Using Java Here we are going to count... it into character array in order to count the occurrence of each character...;ch= third[counter];   int count=0;   for 
Count Rows - JSP-Servlet
Count Rows  How to count rows in Java. Thanks
count in hibernate .
count in hibernate .  How to implements count in hibernate
Java count frequency of words in the string
Java count frequency of words in the string. In this tutorial, you will learn how to count the occurrence of each word in the given string. String...;; } str = str.toLowerCase(); int count = -1; for (int i = 0; i < str.length
Java xml count occurrence of elements
Java xml count occurrence of elements Java provides xml parsers to read... parsers for different purposes. Here we will count the number of occurrences... Integer(1)); } else { int count = ((Integer) value).intValue
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I... No. of found I get XTSM/XTS/TRX/XHAN and now i want count total of this ZHTYPE...); } if (xtsMap.containsKey(rec.getXts())) { Integer count = xtsMap.get(rec.getXts
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I... No. of found I get XTSM/XTS/TRX/XHAN and now i want count total of this ZHTYPE...); } if (xtsMap.containsKey(rec.getXts())) { Integer count = xtsMap.get
Java count characters from file
Java count characters from file In this section, you will learn how to count... into character array in order to count the occurrence of each character...++) { char ch = third[counter]; int count = 0; for (int i = 0; i <
count the users?
count the users?  how to get the number of users logged in any application
Count number of "*"
Count number of "*"  I have this code to count the number of * from...:"); String text = bf.readLine(); int count = 0; for (int i = 0; i...); if (c=='*' ) { count
count characters
count characters  i have to print the total number of char 'A' in all... sabah sarawak terengganu the output must be count the total number of char... main(String[] args) { int count=0; Scanner input=new Scanner
Count Vowels
Count Vowels   Read a string from the user, your program counts the number of vowels in the text and have it report a sum of each vowel found as well as the number of spaces. Make it in two classes
Count Characters from the input string Java
Count Characters from the input string of Java In this section, you will learn how to count the occurrence of each character in the string. For this, we have... to count the occurrence of each character of the array.  Here is the code
Java Count word occurrence and export it to excel file
Java Count word occurrence and export it to excel file Here is an example of scanning a text file in a local drive, and count the frequency of each word in the text file or you can say count the number or occurrence of each word
how to count no.of sheets in excel through POI jar as well as through Java?
how to count no.of sheets in excel through POI jar as well as through Java... know the method to count the no.of sheets in excel through POI jar or else java... will be dynamic ) .I want to read all sheets one by one in java by using POI jar. I
Character count by while loop
Character count by while loop  Write the program to count the number...]; int count=0; for ( int i=0; i<third.length; i++){ if (ch==third[i]) count++; } boolean flag=false; for(int j=counter-1;j>=0;j--){ if(ch==third[j
count objects php
count objects php  How to Count and show objects in PHP
Count Row - JSP-Servlet
Count Row  Hello all, Please I need your help on how to desplay... using java servlet and html form. Thanks for your good job!   Hi friend... db = "register"; String driver = "com.mysql.jdbc.Driver"; int count= 0
Java count occurrence of number from array
Java count occurrence of number from array Here we have created an example that will count the occurrence of numbers and find the number which has the highest occurrence. Now for this, we have created an array of 15 integers
SQLl query count and group by
SQLl query count and group by  How to write a sql query to count and group by the data?   Sql query to count the data and group the data using group by function... Select Name, Count(Name) As Count From Table Group
Hibernate Criteria Count Example
Hibernate Criteria Count Example  Example of Hibernate Criteria Count. Check the tutorial Hibernate Criteria Count. Check the Latest tutorials, articles and examples of Hibernate Framework. Thanks
php array loop count
php array loop count  Count the array using loop in php
Count instances of each word
Count instances of each word  I am working on a Java Project that reads a text file from the command line and outputs an alphabetical listing of the words preceded by the occurrence count. My program compiles and runs
MySQL Count
MySQL Count       This example illustrates how to use count() in MySQL database. Count(): The Count.... It returns a numeric value. If you use COUNT(*) that counts the number of rows.  
retain count in Objective C
retain count in Objective C  what is the retain count in Objective C?   retainCount in Objective c retainCount: retain count method is used to show the internal count of the given object so that programmer can easily
Count distinct value in HQL.
Count distinct value in HQL.  How do you count distinct value in HQL?   count(distinct fieldName) returns number of distinct value... = sessionFactory.openSession(); String countHql = "Select count(distinct salary
Hibernate criteria count.
Hibernate criteria count.  How do we count rows using criteria in hibernate?   We can get the rows count using the Projections. My code is like this: Criteria criteria = session.createCriteria(getReferenceClass
Hibernate criteria count.
Hibernate criteria count.  How do we count rows using criteria in hibernate?   Create hibernate configuration file (hibernate.cfg.xml... create Persistent class ?Hibernate uses the Plain Old Java Object (POJO) classes
Hibernate Count
In this section you will learn different way to count number of records in a table
 

 

 

DMCA.com