PreparedStatement does not initialize (stm="stm" is not a known variable in the current context.)

-1

PreparedStatement declared does not initialize There is an error in line 83, the stm declared in line 21 is not initialized.

import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

public class Rascunho {

    // DAO
    private static String URL;
    private static Connection conn;
    private static PreparedStatement stm;
    private static ResultSet rs;
    private static String USER;
    private static String PASSWORD;

    public static void main(String[] args) {
        URL = "jdbc:firebirdsql://localhost:3050/c:\Users\Vagner\Desktop\Java2014\DB\CLINICA.FDB";
        USER = "SYSDBA";
        PASSWORD = "masterkey";

        WDB_Conecta();

        //****************************************************************
        if (Cliente_Existe(1) == 0) {
//Rotinas de salvamento
            JOptionPane.showMessageDialog(null, "Cliente NÂO Existe");
        } else {
//Rotinas de Atualização
            JOptionPane.showMessageDialog(null, "Cliente Existe");
        }
        //****************************************************************


        try {
            conn.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            StringWriter errors = new StringWriter();
            e.printStackTrace(new PrintWriter(errors));

            JOptionPane.showMessageDialog(null, errors.toString(), e.getMessage(), JOptionPane.ERROR_MESSAGE);
        }
    }

    private static void WDB_Conecta() {

        JOptionPane.showMessageDialog(null, "Iniciando Conecção");

        try {
            conn = DriverManager.getConnection(URL, USER, PASSWORD);
            JOptionPane.showMessageDialog(null, "Conectado com Sucesso");

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            StringWriter errors = new StringWriter();
            e.printStackTrace(new PrintWriter(errors));

            JOptionPane.showMessageDialog(null, errors.toString(), e.getMessage(), JOptionPane.ERROR_MESSAGE);
        }

    }



    private static int Cliente_Existe(int iCodigo) {
        int bol = 0;
        String SQL;

        SQL = "SELECT COUNT(*) AS TOTAL FROM TBCLIENTE WHERE TBCLIENTE.CODIGO = ?)";

        try {
            stm = conn.prepareStatement(SQL);
            stm.setInt(1, iCodigo);
            rs = stm.executeQuery();

            if (rs.getInt("TOTAL") > 0) {
                bol = 1;
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            StringWriter errors = new StringWriter();
            e.printStackTrace(new PrintWriter(errors));

            JOptionPane.showMessageDialog(null, errors.toString(), e.getMessage(), JOptionPane.ERROR_MESSAGE);
        }

        return bol;
    }


}//FIM
    
asked by anonymous 26.01.2015 / 15:48

1 answer

1

SQL = "SELECT COUNT(*) AS TOTAL FROM TBCLIENTE WHERE TBCLIENTE.CODIGO = ?)";

Should ) really be at the end of the query? I think this is the problem.

    
26.01.2015 / 16:55