Java and access

Forum destinado a Linguagem JAVA! Classes, orientação a objeto, conexão com banco, chamada de procedures, etc
Post Reply
connor
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Posts: 1
Joined: Wed, 15 Jun 2016 6:33 pm

Good evening,
I have been attempting to account for the rows of the table of a database and that I will be returned to volar to then start a count in Java.
My problem is that I enter the sql code and it does not give me the value of the count of the columns.

I'll leave the code here.

Select all

 
try{ 
            String query = 
                    "SELECT COUNT(*) FROM Clientes="; 
            System.out.println("query: " +query); 
Can anyone help me?
User avatar
adrianoturbo
Moderador
Moderador
Posts: 393
Joined: Thu, 20 Mar 2008 4:09 pm
Location: Brasília
Adriano Alves
---Para cada problema dificil existe uma solução simples.----

Brother, create a class like this:

Select all

 
//Create a Statement class to execute the SQL statement 
Statement stmt = con.createStatement(); 
 
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) AS COUNT FROM 
CLIENTES"); 
 
 while(rs.next()) { 
    System.out.println("The count is " + rs.getInt("COUNT")); 
 } 
 
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests