Advertisement
Guest User

Untitled

a guest
Sep 12th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.PreparedStatement;
  3. import java.sql.ResultSet;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class hospital{
  8.     public static void main(String[] args){
  9.         Connection con = null;
  10.         PreparedStatement st= null;
  11.         ResultSet rs = null;
  12.  
  13.         String url = "jdbc:mysql://localhost:3306/hospital";
  14.         String user = "ripefruit";
  15.         String password = "secretpassword";
  16.  
  17.         System.out.println("Attempting to connect...");
  18.         try{
  19.             con = DriverManager.getConnection(url, user, password);
  20.             System.out.println("Connected to database!");
  21.             st = con.prepareStatement("select * from Patient");
  22.             rs = st.executeQuery();
  23.         } catch (SQLException e){
  24.             System.out.println("Cannot connect to the database!");
  25.             System.out.println(e);
  26.         }
  27.  
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement