Ae vou colocar o meus dois métodos… o conectar e o gravar o que terei que modificar neles…
public boolean gravar()
{
System.out.println("entrou no gravar");
String sql = "insert into tbAtendimento values ('"+ this.vendedor +"','"+ this.data +"','" + this.filial +"','"+ this.contato +"','"+ this.nomeFanta +"','"+ this.razaoSoc +"','"+ this.cargo +"','"+ this.dpto +"','"+ this.ramoAtiv +"','"+ this.end +"','"+ this.num +"','"+ this.bairro +"','"+ this.cidade +"','"+ this.compl +"','"+ this.cep +"','"+ this.uf +"','"+ this.clienteSN +"', '"+ this.numFunc +"' , '"+ this.telContato +"','"+ this.fax +"','"+ this.email +"','"+ this.site +"','"+ this.possui +"','"+ this.qual +"','"+ this.interesseCli +"','"+ this.pricCarac +"','"+ this.prodFaz +"','"+ this.modelo +"','"+ this.valorItem +"','"+ this.qtd +"' , '"+this.total+"' ,'"+ this.dtRetorno +"')";
System.out.println(sql);
try
{
System.out.println("passou gravar");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("conectou gravar");
Connection conn = DriverManager.getConnection(driver,"","");
System.out.println("passou pelo conn gravar");
PreparedStatement pst = conn.prepareStatement(sql);
System.out.println("chamou o Statement gravar");
pst.executeUpdate();
System.out.println("executou o Statement gravar");
//conn.close();
return true;
}
catch (SQLException s)
{
if (s.getErrorCode() == 2627)
{
JOptionPane.showMessageDialog(null, "Chave primária duplicada!", "ERRO", 0);
return false;
}
else
{
JOptionPane.showMessageDialog(null, "Erro inexperado.\n Entre em contato com o desenvolvedor e informe este número: " + s.getMessage(), "ERRO", 0);
return false;
}
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
Esse é o CONECTAR
public void conectar()
{
System.out.println("entrou");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(driver,"","");
System.out.println("conectou");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Erro na conexão!","Erro",1);
}
}
Tentei fazer um método conectar da seguinte forma
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
public class Conexao
{
private static final String URL = "jdbc:mysql://localhost";
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String USUARIO = "root";
private static final String SENHA = "123";
public static Connection abreConexao() throws SQLException
{
System.out.println("ENTROU NO CONECTAR");
try
{
Class.forName(DRIVER);
System.out.println("PASSOU NO forName");
return (Connection) DriverManager.getConnection(URL,USUARIO,SENHA);
}
catch (ClassNotFoundException e)
{
throw new SQLException(e.getMessage());
}
}
public Conexao() throws SQLException
{
abreConexao() ;
System.out.println("CONECTOU COM SUCESSO");
}
}
O que eu devo modificar em cada método… ?