Advertisement
Guest User

Untitled

a guest
Jun 9th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package SqlConnection;
  2.  
  3. /**
  4.  * Created by Sergio on 6/8/2016.
  5.  */
  6.  
  7. import java.sql.*;
  8. import java.sql.ResultSet;
  9.  
  10.  
  11. public class SqlConnection
  12. {
  13.     public static void main(String[] args)
  14.     {
  15.         try
  16.         {
  17.             String host = "jdbc:sqlserver://localhost:1433;databaseName=Arkus_Test;user=sa;password=7g8hc9trn";
  18.             Connection con = DriverManager.getConnection(host);
  19.             Statement stmt = con.createStatement();
  20.             String SQL = "SELECT * FROM Mails";
  21.             ResultSet rs = stmt.executeQuery(SQL);
  22.  
  23.             while (rs.next())
  24.             {
  25.                 int id_col = rs.getInt("MailID");
  26.                 String correo = rs.getString("Mail");
  27.                 String password = rs.getString("Password");
  28.  
  29.                 System.out.println(id_col + " " + correo + " " + password);
  30.             }
  31.  
  32.             con.close();
  33.  
  34.         }
  35.  
  36.         catch (SQLException err)
  37.         {
  38.             System.out.println(err.getMessage());
  39.  
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement