Olá pessoal estou tendo problemas com o meu projeto é o seguinte não acusa erro no projeto eu staro o derby e tudo bem ele está pronto dou RUN java application abre projeto eu preencho os campos de cadastro dos clientes clico em grava e desaparece os dados digitados acredito que foi gravado… mas quando busco não busca os campos abaixo vou colocar os códigos.
Minha Classe:
[code]package beans;
//import java.util.Vector;
public class Caixa {
//atributos
private int codigo;
private String data;
private float saldoInicial, saldoFinal, valor;
private String obs;
//metodos
public int getCodigo() {
return codigo;
}
public void setCodigo(int codigo) {
this.codigo = codigo;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getObs() {
return obs;
}
public void setObs(String obs) {
this.obs = obs;
}
public float getSaldoFinal() {
return saldoFinal;
}
public void setSaldoFinal(float saldoFinal) {
this.saldoFinal = saldoFinal;
}
public float getSaldoInicial() {
return saldoInicial;
}
public void setSaldoInicial(float saldoInicial) {
this.saldoInicial = saldoInicial;
}
public float getValor() {
return valor;
}
public void setValor(float valor) {
this.valor = valor;
}
}[/code]
exessão:
package excecoes;
public class ContatoNaoExisteException extends Exception
{
private static final long serialVersionUID = 1L;
public ContatoNaoExisteException(String message)
{
super(message);
}
}[/code]
----------------------------------------------------------------------------------------------------------------------------------
Interface:
----------------------------------------------------------------------------------------------------------------------------------
[code]
package interfaces;
import excecoes.ContatoNaoExisteException;
public interface Percistencia
{
void gravar(Object obj);
Object buscar(Object obj) throws ContatoNaoExisteException;
void excluir (Object obj);
void alterar (Object obj);
}
// O Vetor Vector buscaTudo(Class classe);
[/code]
----------------------------------------------------------------------------------------------------------------------------------
Layout
----------------------------------------------------------------------------------------------------------------------------------[code]
package interfaces;
import excecoes.ContatoNaoExisteException;
public interface Percistencia
{
void gravar(Object obj);
Object buscar(Object obj) throws ContatoNaoExisteException;
void excluir (Object obj);
void alterar (Object obj);
}
// O Vetor Vector buscaTudo(Class classe);
Main
package layout;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
public class Inicio extends JFrame{
private static final long serialVersionUID = 1;
private JMenuBar jmBarraMenus = new JMenuBar();
private JMenu mCadastro, mAjuda;
private JDesktopPane telaInterna;
public Inicio(){
super("ELETRÔNICA");
telaInterna = new JDesktopPane();
this.setSize(670,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getRootPane().setJMenuBar(jmBarraMenus);
// exibe a tela
this.setVisible(true);
this.add(telaInterna);
mCadastro = new JMenu();
mAjuda = new JMenu();
mCadastro.setText("Cadastro");
mAjuda.setText("Ajuda");
jmBarraMenus.add(mCadastro);
jmBarraMenus.add(mAjuda);
JMenuItem miCadastroCliente = new JMenuItem();
JMenuItem miCadastroFuncionario = new JMenuItem();
JMenuItem miCadastroFornecedor = new JMenuItem();
JMenuItem miCadastroPecas = new JMenuItem();
JMenuItem miCadastroCargo = new JMenuItem();
JMenuItem miCadastroCompras = new JMenuItem();
JMenuItem miCadastroContasPagar = new JMenuItem();
JMenuItem miCadastroParcelaReceber = new JMenuItem();
JMenuItem miCadastroVendas = new JMenuItem();
JMenuItem miCadastroCaixa = new JMenuItem();
JMenuItem miAjuda = new JMenuItem();
miAjuda.setText("Ajuda é no Google" + " ");
mAjuda.add(miAjuda);
// nomes dos items do menu cadastrar
miCadastroCliente.setText("Cadastrar Clientes");
miCadastroFuncionario.setText("Cadastrar Funcionarios");
miCadastroFornecedor.setText("Cadastrar Fornecedors");
miCadastroPecas.setText("Cadastrar Pecas");
miCadastroCargo.setText("Cadastrar Cargos");
miCadastroCompras.setText("Cadastrar Compras");
miCadastroContasPagar.setText("Cadastrar Contas a Pagar");
miCadastroParcelaReceber.setText("Cadastrar Parcelas a Receber");
miCadastroVendas.setText("Cadastrar Vendas");
miCadastroCaixa.setText("Cadastrar Caixa");
// adicionar itens nos menus
mCadastro.add(miCadastroCliente);
mCadastro.add(miCadastroFuncionario);
mCadastro.add(miCadastroFornecedor);
mCadastro.add(miCadastroPecas);
mCadastro.add(miCadastroCargo);
mCadastro.add(miCadastroCompras);
mCadastro.add(miCadastroContasPagar);
mCadastro.add(miCadastroParcelaReceber);
mCadastro.add(miCadastroVendas);
mCadastro.add(miCadastroCaixa);
telaInterna.setLayout(new BorderLayout());
miCadastroCliente.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroCliente CadCliente = new CadastroCliente();
telaInterna.add(CadCliente);
}
}
);
//==============================================================
miCadastroFuncionario.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroFuncionario CadFuncionario = new CadastroFuncionario();
telaInterna.add(CadFuncionario);
}
}
);
//==============================================================
miCadastroFornecedor.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroFornecedor CadFornecedor = new CadastroFornecedor();
telaInterna.add(CadFornecedor);
}
}
);
//==============================================================
miCadastroPecas.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroPecas CadPecas = new CadastroPecas();
telaInterna.add(CadPecas);
}
}
);
//==============================================================
miCadastroCaixa.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroCaixa CadCaixa = new CadastroCaixa();
telaInterna.add(CadCaixa);
}
}
);
//===============================================================
miCadastroCargo.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroCargo CadCargo = new CadastroCargo();
telaInterna.add(CadCargo);
}
}
);
//================================================================
miCadastroCompras.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroCompras CadCompras = new CadastroCompras();
telaInterna.add(CadCompras);
}
}
);
//=================================================================
miCadastroContasPagar.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroContasPagar CadContasPagar = new CadastroContasPagar();
telaInterna.add(CadContasPagar);
}
}
);
//===================================================================
miCadastroParcelaReceber.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroParcelaReceber CadParcelaReceber = new CadastroParcelaReceber();
telaInterna.add(CadParcelaReceber);
}
}
);
//====================================================================
miCadastroVendas.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
CadastroVendas CadVendas = new CadastroVendas();
telaInterna.add(CadVendas);
}
}
);
//=========================================================================
miAjuda.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ev){
JOptionPane.showMessageDialog(null, "Duvidas" +
JOptionPane.INFORMATION_MESSAGE);
}
}
);
//==============================================================
}
public static void main(String[] args)
{
new Inicio();
}
}
Persistência:
----------------------------------------------------------------------------------------------------------------------------------[code]
package persistencia;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import beans.Caixa;
import excecoes.ContatoNaoExisteException;
public class PersistenciaCaixa {
static PreparedStatement stmt;
public PersistenciaCaixa() {
}
//==============================================
public Object buscar(Object obj) throws ContatoNaoExisteException
{
Caixa caixa = (Caixa) obj;
java.sql.ResultSet rs;
try {
stmt = PersistenciaConexao.conexao.prepareStatement
("select * from tb_caixa where codigo=?");
stmt.setInt(1, caixa.getCodigo());
rs = stmt.executeQuery();
if (rs.first())
{
caixa.setCodigo (rs.getInt("codigo"));
caixa.setData (rs.getString("data"));
caixa.setSaldoInicial (rs.getFloat("saldoinicial"));
caixa.setSaldoFinal (rs.getFloat("saldofinal"));
caixa.setValor (rs.getFloat("valor"));
caixa.setObs (rs.getString("obs"));
return caixa;
}
else
throw new ContatoNaoExisteException("O caixa " + caixa.getCodigo() +
" não está cadastrado");
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
//==============================================
public void gravar(Object obj)
{
Caixa caixa = (Caixa) obj;
try {
stmt = PersistenciaConexao.conexao
.prepareStatement("insert into tb_caixa(codigo, data, saldoinicial, " +
"saldofinal, valor, obs)" +
"values(null,?,?,?,?,?)");
stmt.setString (1, caixa.getData());
stmt.setFloat (2, caixa.getSaldoInicial());
stmt.setFloat (3, caixa.getSaldoFinal());
stmt.setFloat (4, caixa.getValor());
stmt.setString (5, caixa.getObs());
stmt.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
// ==========================================================================
public void excluir(Object obj)
{
Caixa caixa = (Caixa) obj;
try {
stmt = PersistenciaConexao.conexao
.prepareStatement("delete from tb_caixa where codigo=?");
stmt.setInt(1, caixa.getCodigo());
stmt.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
//==========================================================================
public void alterar(Object obj) {
try {
Caixa caixa = (Caixa) obj;
stmt = PersistenciaConexao.conexao
.prepareStatement("update tb_caixa set data=?, saldoinicial=?, " +
"saldofinal=?, valor=?, obs=? where codigo=?");
stmt.setString (1, caixa.getData());
stmt.setFloat (2, caixa.getSaldoInicial());
stmt.setFloat (3, caixa.getSaldoFinal());
stmt.setFloat (4, caixa.getValor());
stmt.setString (5, caixa.getObs());
stmt.setInt (6, caixa.getCodigo());
stmt.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
// ==========================================================================
public Vector buscarTudo(){
ResultSet rs;
Vector<Caixa> caixa = new Vector<Caixa>();
try {
stmt = PersistenciaConexao.conexao.prepareStatement
("select * from tb_caixa");
rs = stmt.executeQuery();
while (rs.next())
{
Caixa cai = new Caixa();
cai.setCodigo (rs.getInt("codigo"));
cai.setData (rs.getString("data"));
cai.setSaldoInicial (rs.getFloat("saldoinicial"));
cai.setSaldoFinal (rs.getFloat("saldofinal"));
cai.setValor (rs.getFloat("valor"));
cai.setObs (rs.getString("obs"));
caixa.add(cai);
}
return caixa;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
}
[/code]
Conexão:
----------------------------------------------------------------------------------------------------------------------------------[code]
package persistencia;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class PersistenciaConexao {
public static Connection conexao;
static {
try{
Class.forName("com.derby.jdbc.Driver");
conexao = DriverManager.getConnection("jdbc:derby:localhost:1527","bancoeletronica","create=true");
}catch(Exception e){
e.printStackTrace();
};
}
public PersistenciaConexao(){
super();
}
public PreparedStatement prepareStatement(String string) {
return null;
}
public static void main(String[] args) {
new PersistenciaConexao();
}
}
[/code]
E assim está a minha tabela:
----------------------------------------------------------------------------------------------------------------------------------[code]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<![CDATA[create table tbcaixa
(
codigo integer ,
data varchar(20),
saldoinicial varchar(20),
saldofinal varchar(20),
valor varchar(20),
obs varchar(30),
primary key(codigo)
);]]]]]]><![CDATA[><![CDATA[>
]]]]><![CDATA[>
]]>
[/code]
Esse são os códigos gerados:
java.lang.ClassNotFoundException: com.derby.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at persistencia.PersistenciaConexao.<clinit>(PersistenciaConexao.java:12)
at persistencia.PersistenciaCliente.gravar(PersistenciaCliente.java:27)
at layout.CadastroCliente$1.actionPerformed(CadastroCliente.java:105)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.NullPointerException
at persistencia.PersistenciaCliente.gravar(PersistenciaCliente.java:28)
at layout.CadastroCliente$1.actionPerformed(CadastroCliente.java:105)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at persistencia.PersistenciaCliente.buscar(PersistenciaCliente.java:57)
at layout.CadastroCliente$4.actionPerformed(CadastroCliente.java:151)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at persistencia.PersistenciaCliente.buscar(PersistenciaCliente.java:57)
at layout.CadastroCliente$4.actionPerformed(CadastroCliente.java:151)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
POR FAVOR AGORA HELP-ME PLES!!! porque não busca, deleta, etc???
Obs.: Eu sei que é extenso o código mas assim fica mais fácil de me ajudarem, eu tenho que apresentar funcionando até sexta.)