Erro de conexão com banco

2 respostas
somma

Pessoal,
Eu tenho está classe de Conexão com o banco de dados:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Conexao {
      
    private static final String URL ="jdbc:odbc:BancoInteligente";
    private static final String DRIVER ="sun.jdbc.odbc.JdbcOdbcDriver";
    private static final String USUARIO ="iperfil1";
    private static final String SENHA ="fernando2006";
    
       
    /** Criando uma nova instancia de Conexao */
    public Conexao() {
    }
    
    public static Connection getConnection() throws SQLException {
        
        try {
            Class.forName(DRIVER);
            System.out.println("JDBC driver loaded");
            return DriverManager.getConnection(URL,USUARIO,SENHA);
            
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    }
    
    public static void fechaConexao(Connection conn, Statement stmt, ResultSet rs) throws SQLException {
    	fechaResultSet(rs);
    	fechaStatement(stmt);
    	fechaConexao(conn);
    }
    
    /**
     * Fecha a Conexão
     */
    public static void fechaConexao(Connection conn) throws SQLException {
    	if(conn != null) {
            conn.close();
    	}
    }

    /**
     * Fecha o Statement
     */
    public static void fechaStatement(Statement stmt) throws SQLException {
    	if (stmt != null) {
            stmt.close();
    	}
    }
    
    /**
     * Fecha o PreparedStatement
     */
    public static void fechaPreparedStatement(PreparedStatement pstmt) throws SQLException {
    	if (pstmt != null) {
            pstmt.close();
    	}
    }
    
    /**
     * Fecha o ResultSet
     */
    public static void fechaResultSet(ResultSet rs) throws SQLException {
    	if (rs != null) {
            rs.close();
	}
    }
}

E através de um SERVLET estou tentado fazer a insert no banco ACCESS.
E insiste em ocorrer o erro de: java.sql.SQLException: No data found

Este é o meu Servlet:

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;
import br.com.iperfil.classe.Conexao;
import br.com.iperfil.classe.CadastreStaff;
import java.sql.*;


public class Staff extends HttpServlet {
    Conexao conexao = new Conexao();
    
    public void init(){        
        try {
            conexao.getConnection();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException{               
         
        int ad_id = 2;
        String ds_Nome              = request.getParameter("s_nome");
        String ds_Endereco          = request.getParameter("s_end");
        
        CadastreStaff cadPessoal = new CadastreStaff();
        cadPessoal.setId(ad_id);
        cadPessoal.setNome(ds_Nome);
        cadPessoal.setEndereco(ds_Endereco);
           
        PreparedStatement statement;
        String sql = "INSERT INTO DadosPessoais(ad_id, ds_Nome, ds_Endereco) VALUES(?,?,?)";
        
         try{
             
                Connection con = conexao.getConnection();
                statement = con.prepareStatement(sql);

                statement.setInt(1,cadPessoal.getId());
                statement.setString(2,cadPessoal.getNome());
                statement.setString(3,cadPessoal.getEndereco());

                statement.executeUpdate();

                conexao.fechaPreparedStatement(statement);
             
         }catch(SQLException e){
            e.printStackTrace();
            System.out.println(e.toString());  
         }
         catch(Exception e){
            System.out.println(e.toString());
             
         }
    }    
}

Quem puder me ajudar eu agradeço!!!!

2 Respostas

somma

Senhores(as),

já descobri o erro!!!

Obrigado

gugaa_df

somma:
Senhores(as),

já descobri o erro!!!

Obrigado

Aonde estava o erro?

Criado 30 de março de 2007
Ultima resposta 31 de mar. de 2007
Respostas 2
Participantes 2