Galera,
Estou com problema na linha da minha classe PaisDao referente ao getConnection. Ele mostra a seguinte mensagem: "Unhandled exception type SQLException". Como posso resolver este problema?
PaisDAO
package br.ccp.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import br.ccp.fabrica.FabricaDeConexao;
import br.ccp.modelo.Pais;
public class PaisDao {
private Connection conection;
public void getConexao(){
this.conection = FabricaDeConexao.getConnection(); //Codigo que está dando mensagem de erro.
}
public void insere(Pais pais)throws SQLException {
PreparedStatement stmt = this.conection.prepareStatement (" insert into pais (pais, capital, idioma, populacao, moeda) values ('"+pais.getPais()+",'"+pais.getCapital()+",'"+pais.getIdioma()+",'"+pais.getPopulacao()+",'"+pais.getMoeda()+")");
stmt.setString(1,pais.getPais());
stmt.setString(2,pais.getCapital());
stmt.execute();
stmt.close();
}
}
FabricaDeConexao
package br.ccp.fabrica;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class FabricaDeConexao {
public static Connection getConnection()throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://localhost:3306/pais", "root", "XXX");
}
catch(ClassNotFoundException ex){
throw new SQLException (ex.getMessage());
}
catch(Exception e){
throw new SQLException (e.getMessage());
}
}
}