count statement that saves results on a variable in a java bean
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 !!
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.
Ads
Related Tutorials/Questions & Answers:
Advertisements
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
Java Bean
Java Bean How to run
java bean program in Netbeans
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
What is instance variable in Java?
What is instance
variable in
Java? Hi,
What is instance
variable in
Java?
What is the use of instance
variable?
Thanks
Hi,
In
Java programming classes are used as base of Object oriented programming. Any
variable
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 Bean
Java Bean What is
Java Bean?
I got my answer already here: http://www.roseindia.net/jsp/usingbeansinjsp.shtml
Thanks a lot
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
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
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
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
Instance variable in java
Instance
variable in
java
In this section you will learn about Instance
variable in
java. In
java all
variable must be declared before they are used... is one of the data type in
java ,identifier is one of the name of the
variable
array variable in a java program
array
variable in a
java program How do i write a program that will prompt the user for a list of 5 prices, that cosist of the sum of all the prices, the average of the prices, and all prices that are higher than the calculated
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 explain about simple if else
statement and complex if else
statement in
java with an example
ModuleNotFoundError: No module named 'saves'
ModuleNotFoundError: No module named '
saves' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
saves'
How to remove the ModuleNotFoundError: No module named '
saves'
How to define a constant variable in Java?
How to define a constant
variable in
Java? Hi,
How to define a constant
variable in
Java?
thanks
HI,
The Constants variables... once its declared. For more related to constant
variable in
java
Thanks
Static variable in java
Static
variable in
java.
Static is a keyword in
java used to create static methods,
variable
inside a class and static class.
Static
variable is also called class
variable which belongs to class not
to object.
Static
Bean
Bean what is
bean? how to use
bean
HTML Code...
JDBC code:
<%@ page language="
java" import ="java.sql.*" %>
<...=DriverManager.getConnection(jdbc:odbc:data,"","");
Statement st=con.CreateStatement("SELECT * FROM
Switch Statement in java 7
Switch
Statement in
java 7
This tutorial describes the if
statement in
java 7. This is one kind of
decision making
statement.
Switch Statements :
The switch
statement is used when you want to test many statements based on
some
conditional statement in java
conditional
statement in java Write a conditional
statement in
Java
Logical and comparison statements in OOPs are also know as conditional statements. You can learn "How to write conditional
statement in
Java " from
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 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
GOTO Statement in java
GOTO
Statement in java I have tried many time to use
java goto
statement but it never works
i search from youtube google but e the example on net are also give compile
error.
if possible please give me some code with example
Use if statement with LOOP statement
Use if
statement with LOOP
statement
 ... with Example
The Tutorial illustrate a example from if
statement with LOOP
statement. In this example we create a procedure display that accept