Galera tenho essas duas classes:
import java.util.*;
import java.io.*;
import java.sql.*;
public class GerenciadorLogin{
private final static Properties props = new Properties();
private final String classPath = "propsJdbc.properties";
public GerenciadorLogin(){
try{
props.load(new FileInputStream(classPath));
}
catch(IOException e){
System.out.println("Erro ao carregar arquivo!");
}
}
public void logar1(String s, String s1){
}
public static void logar(String user, String login) throws SQLException {
try{
System.out.println("Procurando Driver...");
Class.forName(props.getProperty("driver"));
System.out.println("Driver encontrado!");
String url = props.getProperty("url");
String userName = props.getProperty("user");
String senha = props.getProperty("login");
Connection con = DriverManager.getConnection(url,"","");
System.out.println("Conectado...");
Statement stm = con.createStatement();
ResultSet rs = stm.executeQuery("select user,login from usuarios where user=userName;");
String u="",s="";
while (rs.next()){
u = rs.getString("user");
s = rs.getString("login");
}
if (u.equals(user) && s.equals(login)){
System.out.println("Usuario e Login corretos");
}
else{
System.out.println("Usuario ou Senha Incorreto");
}
}
catch(ClassNotFoundException e){
System.out.println("Classe nao encontrada");
}
catch(SQLException sqle){
System.out.println("Erro no SQL");
}
}
}
[b]essa de cima compilou certinho…porem essa outra, quando vou chamar o método logar da classe OuvinteBtnOk, me da o seguinte erro de exceção: “unreported exception java.SQLException; must be caught or declared to be throw”
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
/**
* Sample application using Frame.
*
* @author
* @version 1.00 06/05/19
*/
public class LoginFrame extends JFrame {
JLabel JLuser = new JLabel("User: ");
JLabel JLlogin = new JLabel("Login: ");
JTextField JTFuser = new JTextField();
JTextField JTFlogin = new JTextField();
JButton JBok = new JButton("OKkkkkk");
/**
* The constructor.
*/
public LoginFrame() {
Container c = getContentPane();
c.setLayout(null);
JLuser.setEnabled(true);
JLuser.setBounds(100,100,50,50);
c.add(JLuser);
JTFuser.setEnabled(true);
JTFuser.setBounds(150,110,100,25);
c.add(JTFuser);
JLlogin.setEnabled(true);
JLlogin.setBounds(100,130,50,50);
c.add(JLlogin);
JTFlogin.setEnabled(true);
JTFlogin.setBounds(150,140,100,25);
c.add(JTFlogin);
JBok.setEnabled(true);
JBok.setBounds(125,170,100,25);
c.add(JBok);
OuvinteBtnOk btnok = new OuvinteBtnOk();
JBok.addActionListener(btnok);
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit = new MenuItem();
menuFile.setLabel("File");
menuFileExit.setLabel("Exit");
menuFileExit.setLabel("ok");
// Add action listener.for the menu button
menuFileExit.addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
LoginFrame.this.windowClosed();
}
}
);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
setTitle("Login");
setMenuBar(menuBar);
setSize(new Dimension(400, 400));
// Add window listener.
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
LoginFrame.this.windowClosed();
}
}
);
}
private class OuvinteBtnOk implements ActionListener {
public void actionPerformed(ActionEvent ae){
GerenciadorLogin.logar(JTFuser.getText(),JTFlogin.getText());
}
}
/**
* Shutdown procedure when run as an application.
*/
protected void windowClosed() {
// TODO: Check if it is safe to close the application
// Exit application.
System.exit(0);
}
}
[size=“11”][color=“red”]* Editado: Lembre-se de utilizar BBCode em seus códigos - Ratinho[/color][/size] :joia:
O estranho, é que no método logar da classe GerenciadorLogin, eu ja declarei que pode ocorrer uma exceção.
Alguem pode me ajudar ?[/b]