PessoAll,

    H� algum tempo atr�s escrevi para esta lista pedindo aux�lio porque
minha aplica��o n�o conseguia estabelecer conex�o com minha aplica��o e
minha base de dados.

    Bem, em desespero de causa, reinstalei a droga do Windows e, tchan
!, tchan !, tchan ! funcionou !!!

    Estou conseguindo incluir, consultar, alterar e excluir, s� que tem
um problema (nem tudo s�o flores !), consigo alterar e excluir, mas
sempre que fa�o isso, meu programa d� erro e termina, ao entrar
novamente verifico que o registro foi alterado ou exclu�do corretamente.
Pelo que li, tenho que mandar o ponteiro do arquivo se possicionar em
outro registro, mas n�o consegui faz�-lo.

    Estou mandando em attach o arquivo, agrade�o se algu�m puder me
ajudar.

                        Gilleanes
import java.io.*;
import java.sql.*;

public class cadchave
 {
 public static void main (String[] args) throws SQLException, IOException
  {
  int codtex, total, op, resul;
  String texto, destex;
   try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException e)
     {
     System.out.println("Nao Consigo Carregar o Driver !");
     e.printStackTrace();
     return;
     }
   Connection conn = DriverManager.getConnection("jdbc:odbc:ac1", "", "");
   Statement stmt = conn.createStatement();

   InputStreamReader le = new InputStreamReader (System.in);
   BufferedReader entra = new BufferedReader (le);

   System.out.println ("Informe o C�digo: ");
   texto = entra.readLine();
   codtex = new Integer(texto).intValue();

   String comando = "Select * from CHAVE where codcha = " + codtex;
   ResultSet rs = stmt.executeQuery (comando);
   total = 0;
   op = 0;
   while (rs.next())
         {
         total ++;
         System.out.println ("C�digo: " + rs.getString(1));
         System.out.println ("Descri��o: " + rs.getString(2));
         op = 0;
         System.out.println ("Deseja <1> Alterar ou <2> Excluir ?");
         texto = entra.readLine();
         op = new Integer(texto).intValue();
         if (op == 1)
            {
            System.out.println ("Informe a descri��o: ");
            texto = entra.readLine();
            destex = new String(texto);
            stmt.executeUpdate ("Update CHAVE set NOMCHAVE = '" + destex + "' where 
codcha = " + codtex);
//            rs.updateString("NOMCHAVE", "' + destex + '");
            }
         if (op == 2)
            {
//            rs.absolute (1);
//            rs.deleteRow();
            String comand2 = "Delete * from CHAVE where codcha = " + codtex;
            resul = stmt.executeUpdate (comand2);
            System.out.println ("Resultado: " + resul);
            rs.first();
            }
         }

   if (total == 0)
      {
      System.out.println ("Informe a descri��o: ");
      texto = entra.readLine();
      destex = new String(texto);
      stmt.executeUpdate("INSERT INTO CHAVE " + "VALUES (" + codtex + ", '" + destex + 
"') ");
      }

   stmt.close();
   conn.close();
   }
  }

------------------------------ LISTA SOUJAVA ----------------------------
http://www.soujava.org.br  -  Sociedade de Usu�rios Java da Sucesu-SP
d�vidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
para sair da lista: envie email para [EMAIL PROTECTED]
-------------------------------------------------------------------------

Responder a