Share on Google+Share on Google+

thanos
count statement that saves results on a variable in a java bean
1 Answer(s)      5 years and 10 months ago
Posted in : Java Beginners

Hello i want to ask you where is the problem and my programme give me only null returns ---> package javalab;

import java.sql.*;

public class History {





    private int w ;
    private int v ;
    private int c ;

    public History() {}

    public String findPrevious(){
        Connection conn = null;
        Statement statement = null;
        String SQLStr ;
        String retString = "";
        ResultSet nu =  null;


        SQLStr = "SELECT COUNT(*) AS COS  FROM dev.history WHERE previous like 1; ";
        SQLStr = "SELECT COUNT(PREVIOUS) AS VOD FROM dev.history WHERE PREVIOUS like 2; ";
        SQLStr = "SELECT COUNT(PREVIOUS) AS WIN FROM dev.history WHERE PREVIOUS like 3 ;";


        try{
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            conn = DriverManager.getConnection("jdbc:mysql://"+
                    "localhost:3306/dev","root","pro");



            statement = conn.createStatement();
            nu = statement.executeQuery(SQLStr);

            if (nu.next())
                c = nu.getInt("COUNT(previous)");
                v = nu.getInt("VOD"); 
                w = nu.getInt("WIN");

        }catch (SQLException sqlEx){
            System.err.println(sqlEx.getMessage());
        }catch (ClassNotFoundException classNotFound){
            System.err.println(classNotFound.getMessage());
        }catch (Exception ex){
            System.err.println(ex.getMessage());
        }finally {
            try
                {if (statement != null){
                    statement.close();
                }
            }catch(final SQLException sqlEx){
                System.err.println(sqlEx.getMessage());
            }
        }
        return retString;
    }

        public int Wind(){
            return w;
        }

        public int Vodafone(){
            return v;
        }
        public int Cosmote(){
            return c;
        }

} thx a lot in advance !!

Ads

View Answers

June 7, 2011 at 5:53 PM


Hi thanos

First i suggest you to go through the following exmaple :

http://www.roseindia.net/jdbc/jdbc-mysql/AllTableName.shtml

Second thing may be if you are running directly this code without public static void main()

If you are running this code by creating object of this class ,and not calling wind(), vodafone() or cosmot() function and directly running findPrevious() function Then it will return surley NULL because it is retuning variable retString which dont have any value.










Related Tutorials/Questions & Answers:
count statement that saves results on a variable in a java bean
count statement that saves results on a variable in a java bean  ...; Statement statement = null; String SQLStr ; String retString = ""; ResultSet nu = null; SQLStr = "SELECT COUNT(*) AS COS FROM
count statement that saves results on a variable in a java bean
count statement that saves results on a variable in a java bean  ...; Statement statement = null; String SQLStr ; String retString = ""; ResultSet nu = null; SQLStr = "SELECT COUNT(*) AS COS FROM
Advertisements
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
How to extract the values of a variable in a href statement. - Java Beginners
How to extract the values of a variable in a href statement.  Hi, Here im trying to send invitations to some selected people.It is working when i...: SENDINVITE Now here i want to put a variable containing multiple e-mail ids
Java Bean
Java Bean  How to run java bean program in Netbeans
Java Bean
Java Bean  What is a Java Bean?   A Java Bean is a software component that has been designed to be reusable in a variety of different environments
Assigning a value to JSP variable from a bean class. - JSP-Servlet
Assigning a value to JSP variable from a bean class.  Hi, I want to know how we can assign value to a JSP variable from a Java Bean. I am using Struts, JSTL. Which tags should I use to assign the value. e.g Kindly
Hibernate DetachedCriteria mutiple results in java
Hibernate DetachedCriteria mutiple results in java  This is the SQL statement that I have. SELECT FIRSTNAME, LASTNAME, USERTYPE FROM USERPROFILE INNER JOIN USERLOGINSTATUS ON USERPROFILE.USERID=USERLOGINSTATUS.USERID ORDER
Java variable
Java variable   To what value is a variable of the String type automatically initialized
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
Java File Handling Test Results
Java File Handling Test Results   Is somebody able to help me with this Write a program to read each name from the file and prompt the user to enter the percentage for that student at the keyboard. I need to input
Java Bean
Java Bean  What is Java Bean?   I got my answer already here: http://www.roseindia.net/jsp/usingbeansinjsp.shtml Thanks a lot
Converting jsp variable to java variable
Converting jsp variable to java variable  Hi how to convert java script variable to java variable on same jsp page
java if statement
java if statement  If statement in Java
Assign value from a <bean:write> tag to a variable
Assign value from a tag to a variable  I am calling a stored procedure from JSP page which needs an input parameter. This input parameter needs to get the value from bean write tag . How can i do that ?   Please go
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
Ask java count
Ask java count  Good morning, I have a case where there are tables... the results: for example: | code book | name of book | sum | | b001 | Java 1 | 10 | | b002 | beginner java | 5
Java Bean Properties
Java Bean Properties  What are the properties of a normal java Bean(Not EJB)   HI Friend, Please visit here: http://www.roseindia.net/jsp/usingbeansinjsp.shtml Thanks
Java Bean - Java Beginners
Java Bean  Sir, How can i add a java bean into a target GUI.... Thanking you Pabitra Kr Debanth.   Hi friend, Java Bean classes must..., it will be a visible Java Bean. Java Beans may also be invisible
JAVA BEAN WITH ORACLE FORMS
JAVA BEAN WITH ORACLE FORMS  Hi..I am doing my final year Project.. I need the ste-by-step procedure to integrate a bean with oracle forms? Please help me
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
java bean - EJB
java bean  difference between java bean and enterprice java bean  first of all dont compare java bean with enterprise java bean because enterprise java bean is a techonology where we can develope business logic
Java Final Variable
Java Final Variable  I have some confusion --Final variable has single copy for each object so can we access final variable through class name,or it is necessary to create object for accessing final variable
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
Switch Statement with Strings in Java
Switch Statement with Strings in Java  Switch Statement with Strings in Java
if else statement in java
if else statement in java  if else statement in java explain with example
Count Records using the Prepared Statement
Count Records using the Prepared Statement  ...\PreparedStatement>java CountRecords Count records example using prepared... to count all records of the database table by using the PreparedStatement
JAVA statement - Java Beginners
JAVA statement  The import statement is always the first noncomment statement in a Java program file.Is it true?  Hi Friend, No,it is not true.If your class belongs to a package, the package statement should
Store Variable in Java
Store Variable in Java  How to store Variables in Java?   public class DoubleTest { public static void main(String[] args) { double...(aDouble); // Outputs 7.21 } }   Variable in Java
if else statement in java
if else statement in java  explain about simple if else statement and complex if else statement in java with an example
java bean code - EJB
java bean code  simple code for java beans  Hi Friend, Java Beans are reusable components. They are used to separate Business logic from.... Java Bean Code: public class EmployeeBean{ public int id; public
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads