Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. package carros;
  3.  
  4. import java.sql.*;
  5.  
  6. /**
  7.  *
  8.  * @author José Bernardo
  9.  */
  10. public class bd {
  11.    
  12.      public void InsereCarro(Carros car) throws ClassNotFoundException {
  13.         {try
  14.             {
  15.                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  16.                 String Database = "jdbc:odbc:carros;"
  17.                 Connection conn = DriverManager.getConnection(Database, "sa", "123");
  18.                 Statement s = conn.createStatement();
  19.                
  20.                 String selTable = "SELECT * FROM Alunos";
  21.                 s.execute(selTable);
  22.                 ResultSet rs = s.getResultSet();
  23.                 while((rs!=null && (rs.next())))
  24.                 {
  25.                     System.out.println(rs.getString(1)+":"+rs.getString(2));
  26.                 }
  27.                
  28.                 String UpdateTelefone = "Update Alunos set telefone='aaa'";
  29.                 s.execute(UpdateTelefone);
  30.                 conn.close();
  31.             }
  32.             catch(SQLException ex)
  33.             {System.out.println(ex.toString());}
  34.          }
  35.      }
  36. }