Bom dia.
Tenho um problema, não sei onde está o erro…Vamos lá:
Meu Login.Java:
package suporte;
public class Login extends javax.swing.JFrame {
public Login() {
initComponents();
}
conexao con = new conexao();
Banco bco = new Banco();
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
btConectar = new javax.swing.JButton();
btLimpar = new javax.swing.JButton();
userTxt = new javax.swing.JTextField();
passTxt = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Perpetua Titling MT", 0, 11));
jLabel1.setText("Login");
jLabel2.setText("Usuario:");
jLabel3.setText("Senha:");
btConectar.setText("Conectar");
btConectar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btConectarActionPerformed(evt);
}
});
btLimpar.setText("Limpar");
btLimpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btLimparActionPerformed(evt);
}
});
userTxt.setText("jTextField1");
userTxt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
userTxtActionPerformed(evt);
}
});
passTxt.setText("jTextField2");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(175, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(182, 182, 182))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(passTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(userTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(134, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(224, Short.MAX_VALUE)
.addComponent(btConectar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btLimpar)
.addGap(20, 20, 20))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(userTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(passTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btConectar)
.addComponent(btLimpar)))
);
userTxt.getAccessibleContext().setAccessibleName("campoUser");
passTxt.getAccessibleContext().setAccessibleName("campoPass");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
[b]private void btConectarActionPerformed(java.awt.event.ActionEvent evt) {
if(con.fazConexao() != null)
{
if(bco.Verificar(userTxt.getText(), passTxt.getText()));
new Registrar().setVisible(true);
dispose();
}
} [/b]
[b]private void btLimparActionPerformed(java.awt.event.ActionEvent evt) {
passTxt.setText("");
userTxt.setText("");
} [/b] private void userTxtActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btConectar;
private javax.swing.JButton btLimpar;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField passTxt;
private javax.swing.JTextField userTxt;
// End of variables declaration
}
Minha classe para conexão:
package suporte;
import java.sql.Connection;
import java.sql.DriverManager;
public class conexao {
private Connection con;
public Connection fazConexao(){
try{
con = null;
String conectando = "jdbc:sqlserver://localhost:1433;databaseName=Suporte;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(conectando,"sa","111");
System.out.println("Conexão feita com sucesso!");
}
catch(Exception e){
e.printStackTrace();
System.err.println(e.getMessage());
}
return con;
}
public void fecharConexao(){
try {
con.close();
} catch (Exception e) {
}
}
}
E a classe do Banco:
package suporte;
import java.sql.*;
public class Banco {
Connection con;
Formulario form;
//--------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------//
public void inserir(String nome, String setor, String problema, String dataRegistro) {
String comando = "insert into tabela1 (nome, setor, problema, dataRegistro) values(?,?,?,?)";
PreparedStatement p;
try {
p = this.con.prepareStatement(comando);
p.setString(1, form.getNome());
p.setString(2, form.getSetor());
p.setString(3,form.getProblema());
p.setDate(4, new java.sql.Date( form.getDataRegistro().getTime() ) );
p.execute();
} catch (SQLException e) {
}
}
public void Verificar(String Nome, String Senha){
String usuario = "usp_usuario ?";
String senha = "usp_senha ?";
PreparedStatement p = null;
try{
p.setString(1, Nome);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(usuario);
}
catch(SQLException e){}
if(usuario.equals(Nome)){
try{
p.setString(1, Senha);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(senha);
}
catch(SQLException e){}
//String senha = "select Senha from tblFormulario where Senha = ? and Nome = ?";
}
private boolean Verificar(String Usuario, String Senha) {
try {
ResultSet rs = con.createStatement().executeQuery("SELECT c_nom_usu,c_sen_usu "
+ "FROM cadusuario "
+ "WHERE c_log_usu ='" + Usuario + "' "
+ "AND c_sen_usu ='" + Senha + "'");
if (rs.next()) {
return true;
} else {
return false;
}
} catch (SQLException ex) {}
return false;
}
//------------------------------------------------------------------------------------------//
//---------------------------------------------------------//
public Formulario Tudo() {
String comando = "select * from Contato";
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(comando);
while( rs.next()){
int protocolo = rs.getInt("protocolo");
String nome = rs.getString("nome");
String setor = rs.getString("setor");
String problema = rs.getString("problema");
Date dataRegistro = rs.getDate("dataRegistro");
form.setProtocolo(protocolo);
form.setNome(nome);
form.setSetor(setor);
form.setProblema(problema);
form.setDataRegistro(dataRegistro);
}
return form;
} catch (Exception e) {
}
return null;
}
}
Estou com um erro de parametros, de tipo, não sei no Verificar.
Por ser Boolean, passar parametros, não estou conseguindo decifrar o problema aqui.