This giving error when I try to insert in my sqlite + java database

Asked

Viewed 68 times

0

package Contas;


import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
import javax.swing.JOptionPane;

import BancoConexao.Banco;

public class ContaCorrente extends Conta{
    public ContaCorrente(int NumConta,String nome,float Saldo,String senha,int tipo) {
        super(NumConta, nome, Saldo, senha, tipo);
    }
    public void Cad() {
        Banco ContCorrente = new Banco();
        ContCorrente.conectar();
        String sql = "INSERT INTO ContaCliente("
                + "NumeroConta,"
                + "Nome,"
                + "Saldo,"
                + "Senha,"
                + "Tipo"
                + ") VALUES(?,?,?,?,?)"
                +";";

            JOptionPane.showMessageDialog(null,"Cadastrado!");
            PreparedStatement prepare = ContCorrente.criarPreparedStatement(sql);

            try{

               //aqui se encontra o erro, neste prepare
                prepare.setInt(1,getNumConta());
                prepare.setString(2,getNome());
                prepare.setFloat(3,getSaldo());
                prepare.setString(4,getSenha());
                prepare.setInt(5,getTipo());
                prepare.executeUpdate();
            }catch(SQLException e){
                System.out.println("Erro ao Cadastrar");
            }finally{
                if(prepare != null){
                    try {
                        prepare.close();
                    } catch (SQLException ex) {
                        System.out.println("Erro ao fechar o banco");
                    }
                }
            }
            ContCorrente.desconectar();
    }    
}
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: ContaCliente)
  at org.sqlite.DB.newSQLException(DB.java:383)
  at org.sqlite.DB.newSQLException(DB.java:387)
  at org.sqlite.DB.throwex(DB.java:374)
  at org.sqlite.NativeDB.prepare(Native Method)
  at org.sqlite.DB.prepare(DB.java:123)
  at org.sqlite.PrepStmt.<init>(PrepStmt.java:42)
  at org.sqlite.Conn.prepareStatement(Conn.java:404)
  at org.sqlite.Conn.prepareStatement(Conn.java:399)
  at org.sqlite.Conn.prepareStatement(Conn.java:383)
  at BancoConexao.Banco.criarPreparedStatement(Banco.java:54)
  at Contas.ContaCorrente.Cad(ContaCorrente.java:27)
  at Principal.main(Principal.java:32)
Exception in thread "main" java.lang.NullPointerException
  at Contas.ContaCorrente.Cad(ContaCorrente.java:30)
  at Principal.main(Principal.java:32)

that’s the mistake you’re giving

  • 1

    "is making a mistake" is very vague. You could [Edit] the question, detailing the error, what data you tried to insert, what the result should be, etc. See also [Ask] and how to provide a [mcve].

  • the question is as clear as possible, I want to insert in the database and is giving error in the line I commented, the result of wanting to insert would not be the insertion of data in the database? how to make it clearer than that? I put the error here?

  • Error when inserting into bank may have several causes. It may be that the value is not of the same type as the column, or is outside the valid values, or lack of permission, etc etc. No more details about the error (what message?), the table and the data you are trying to enter (getNumConta() returns what? ), we have no way to guess what is happening. Try to imagine yourself in place of the other users of the site who do not know your system, are not in the same context as you and the only thing they have is what is in the question. So I’d say yes, you can make it clearer

  • Edit your answer and add the stack trace with the error.

  • This link contains an explanation that may seem a little rude, but I suggest you read: https://pt.meta.stackoverflow.com/a/5484/112052

  • "no such table: Contacliente" - table does not exist (or user does not have permissions in this table). You have already checked this?

  • i created the database and connected in java, the table exists

  • I don’t know Sqlite that well, but it might help you: https://stackoverflow.com/questions/14998695/java-missing-database-error

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.