
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 !!

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.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.