0
I’m trying to run the table, but in netbeans it keeps alerting the error in the Executequery line.
Symbol: method executeQuery(String) Location: variable stmt of type Statement
The error is underlined, netbeans warns that the above message on the part of the executaeQuery.
Follow the code.
Connected Class
package Model;
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Conexao {
public Connection con;
public Statement stmt;
public ResultSet rs;
//Connect Mysql Endereço
String url ="jdbc:mysql://localhost/";
String driver = "";
String user = "";
String password = "";
//Metodos
public void Connectar(){
try{
Class.forName(driver);
con = DriverManager.getConnection(url,user,password);
stmt = (Statement) con.createStatement();
}catch(Exception e){
}
}
//TESTANDO OUTRO TIPO DE CHAMADA BANCO DE DADOS
/*public static Connection creatConnection() throws SQLException{
String url ="jdbc:mysql://localhost/id6275581_unit";
String user = "id6275581_unitusername";
String password = "123456";
Connection conexaos = null;
conexaos = DriverManager.getConnection(url,user,password);
return conexaos;
}*/
}
Login class
package View;
import Model.Conexao;
import java.beans.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class Login extends javax.swing.JFrame {
public Login() {
initComponents();
}
public void acessar(){
try{
Conexao connect = new Conexao();
connect.Connectar();
connect.stmt = (Statement) connect.con.createStatement();
String sql = "SELECT * FROM login";
//ResultSet rsTeste = connect.stmt.executeQuery(sql);
// PreparedStatement ps = connect.con.prepareStatement(sql);
connect.rs = connect.stmt.executeQuery(sql);
//ResultSet rss = ps.executeQuery();
//ps.execute();
connect.rs.first();
if((txtUsuario.getText().equals(connect.rs.getString("username"))) && (txtSenha.getText().equals(connect.rs.getString("password")))){
}else{
//AJAX FUTURO
JOptionPane.showMessageDialog(null,"Senha ou Login Incorreto");
}
}catch(SQLException e){
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
label1 = new java.awt.Label();
label2 = new java.awt.Label();
label3 = new java.awt.Label();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
txtUsuario = new javax.swing.JEditorPane();
txtSenha = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Sisterma Login");
setBackground(new java.awt.Color(0, 153, 102));
setResizable(false);
label1.setFont(new java.awt.Font("Arial", 0, 20)); // NOI18N
label1.setText("Sistema Academico - Login");
label2.setText("Usúario:");
label3.setText("Senha:");
jButton1.setText("Logar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Cadastre");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
txtUsuario.setName("txtUsuario"); // NOI18N
jScrollPane2.setViewportView(txtUsuario);
txtSenha.setName("txtSenha"); // NOI18N
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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(18, 18, 18)
.addComponent(jButton1)
.addGap(31, 31, 31))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtSenha)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addGap(63, 63, 63)
.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 93, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(38, 38, 38)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(20, 20, 20)
.addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(txtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap())
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.acessar();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Cadastro cadastro = new Cadastro();
cadastro.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JScrollPane jScrollPane2;
private java.awt.Label label1;
private java.awt.Label label2;
private java.awt.Label label3;
private javax.swing.JPasswordField txtSenha;
private javax.swing.JEditorPane txtUsuario;
// End of variables declaration
}
Vitor, what error? How do we guess what this is about? You need to show the error to us because your code is not executable.
– user28595
boy I’ll take the print , the netbens is informing me oerro, at last see the print.
– Vitor
No error yet. Your print helped little. Hover mouse over the red griffin q the netbeans shows the error in a yellow box.
– user28595
already passed, but it informs that it is only an error, Symbol: method executeQuery(String) Location: variable stmt of type Statement
– Vitor
do not give yellow option
– Vitor
Dude, just with little bits of code and without being able to execute is difficult to help ne. Edit the pegunta and put the two involved classes complete.
– user28595
I edited the complete code.
– Vitor
Impossible to know the error without Cvoce had not presented the complete code. See the answer with the solution below.
– user28595