Advertisement
Guest User

Untitled

a guest
May 1st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.sql.DriverManager;
  2. import java.sql.Connection;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. public class conexao {
  8.     public static void main(String[] args)
  9.     {
  10.         try {
  11.             Class.forName("com.mysql.jdbc.Driver");
  12.             String url = "jdbc:mysql://localhost:3306/t2ti";
  13.             Connection con = DriverManager.getConnection(url,"root","h2vc2304");
  14.             System.out.println("con: "+con);
  15.             Statement Statement = con.createStatement();
  16.             //Statement.executeUpdate("Insert into clietes (rg,nome) values (4,'fulano')");
  17.            
  18.             ResultSet rs = Statement.executeQuery("Select * from clietes");
  19.             if(rs.first())
  20.             {
  21.                 do
  22.                 {
  23.                     System.out.println("Nome: "+rs.getString("nome"));
  24.                 }while(rs.next());
  25.             }
  26.            
  27.         } catch (ClassNotFoundException e) {
  28.             e.printStackTrace();
  29.         } catch (SQLException e) {
  30.             e.printStackTrace();
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement