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



Home Answers Viewqa Java-Beginners count statement that saves results on a variable in a java bean
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


thanos
count statement that saves results on a variable in a java bean
1 Answer(s)      3 years and 7 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 !!


Advertisement
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
Java variable
Java variable   To what value is a variable of the String type automatically initialized
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
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 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 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 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 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
if else statement in java
if else statement in java  if else statement in java explain with example
Switch Statement with Strings in Java
Switch Statement with Strings in Java  Switch Statement with Strings in Java
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 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
Advertisements
 

 

 

DMCA.com