Erro no PrepareStatement, (tó pirando)

5 respostas
G

Qual o erro pessoal?

import java.sql.*;
public class pirei {
   public static void main( String args[] ){
		String driveOdbc = "sun.jdbc.odbc.JdbcOdbcDriver";
		String pathOdbc = "jdbc:odbc:CADASTRO";
		Connection con;
			   		
		String psqSql = "update CLIENTES set NOME = ?, SALARIO = ?, NASCIMENTO = ?  where cpfcgc = ?"; 
		try {
			Class.forName(driveOdbc);
			con = DriverManager.getConnection(pathOdbc ,"","");
		} 	
		catch (java.lang.ClassNotFoundException er1) {
			System.out.println("Não conectou");
		}
		catch (SQLException er2) {		
			System.out.println("Não conectou");
		}

//		Conecta legal, quando chega aqui (foi.....)		
		PrepareStatement pStmt = con.prepareStatement( psqSql );  	
   }
}

5 Respostas

Rafael_Steil

Ola,
qual o erro que esta dando para voce? coloque aqui a mensagem de erro que da ao executar o programa, pois isso ajudara muito a tentar resolver o problema.

Rafael

ozielneto

Tente completar a classe assim…

PrepareStatement pStmt = con.prepareStatement( psqSql );

pStmt.setString(1, nome); // campo texto

pStmt.setDouble(2, salario); // campo numerico

pStmt.setDate(3, new Date() ); // campo data

pStmt.setString(4, cpf ); // campo texto.

int row = pStmt.executeUpdate();

pStmt.close();

con.close();
G
import java.sql.*;
import java.util.Date;

public class pirei {
	public static void main( String args[] )
	{     
	
  		String psqSql = "update CLIENTES set NOME = ?, SALARIO = ?, NASCIMENTO = ?  where cpfcgc = ?"; 	
		String driveOdbc = "sun.jdbc.odbc.JdbcOdbcDriver";
		String pathOdbc = "jdbc:odbc:CADASTRO";
		Connection con;	
		
		try {
			Class.forName(driveOdbc);
			con = DriverManager.getConnection(pathOdbc ,"","");
		} 	catch (java.lang.ClassNotFoundException er1) {
				System.out.println("Erro ao conectar");
			}
					
			catch (SQLException er2) {		
				System.out.println("Erro ao conectar");
			}
				
		System.out.println("Conectei");
		
		PrepareStatement pStmt = con.prepareStatement( psqSql ); 
		pStmt.setString(1, "artur cesar");
		pStmt.setDouble(2, new Double(1234.42)); 
		pStmt.setDate(3, new Date() );
		pStmt.setString(4, "[telefone removido]" ); 
		int row = pStmt.executeUpdate(); 
		pStmt.close(); 
		con.close();
	}
}

******************* erro ***********************

pirei.java:28: cannot resolve symbol symbol : class PrepareStatement location: class pirei PrepareStatement pStmt = con.prepareStatement( psqSql ); ^ 1 error
P

PreparedStatement pStmt = con.prepareStatement( psqSql );

naum seria isso??

te mais!

Paulo_Silveira

como a paola disse, voce tem um TYPO ai

eh PrepareD (com D no final)

Criado 1 de abril de 2003
Ultima resposta 2 de abr. de 2003
Respostas 5
Participantes 5