gente sei que ja tem muita questao relacionados a banco de dados
mas eu estou fazendo uma aula de conexao e queria fazer do seguinte modo.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.sisvenda.acessobd;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author jorge
*/
public class AcessoSqlServer {
Connection con;
PreparedStatement pstm;
ResultSet rs;
public static void main(String[] args){
new AcessoSqlServer();
}
public AcessoSqlServer(){
conectar();
}
public void conectar(){
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;database=SYSVENDA;user=sa;password=08022005;");
} catch (ClassNotFoundException ex) {
System.out.println("Não foi possivel encontrar o Driver !!!");
} catch (SQLException ex){
System.out.println("Não foi possivel conectar ao banco !!!");
}
}
public void desconectar(){
try {
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
mas no netbeans me mostra um erro no fechamento do bloco do metodo conectar chamado
“unreported exception SQLException;must be caught or declared to be thrown”
como posso proceder para ajeitar esse codigo.