Guest User

Untitled

a guest
Jun 4th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package com.hospital.emr;
  2.  
  3. import java.sql.*; // need to import the java.sql package to use JDBC
  4. //import java.util.ArrayList; // needed for arraylist
  5.  
  6.  
  7. public class JdbcConnection
  8. {
  9.    
  10.     Connection conn;
  11.     Statement stmt;
  12.    
  13.     ResultSet rset;
  14.     //ArrayList<ResultSet> rset = new ArrayList<ResultSet>(); // create an arraylist of result sets
  15.    
  16.     // constructors
  17.     public JdbcConnection()
  18.         throws SQLException
  19.     {
  20.         // Load the Oracle JDBC driver
  21.         DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  22.                
  23.         // Connect to the database
  24.         Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.128:1521:xe", "hr","password");
  25.                
  26.         // Create a Statement
  27.         Statement stmt = conn.createStatement();
  28.                
  29.         System.out.println("Database connection successful.");
  30.     }
  31.    
  32.  
  33.     // not sure if this should go in LoginActivity.java or here??
  34.     public void CheckLogin(String username, String password)
  35.     {
  36.        
  37.         try {
  38.             rset = stmt.executeQuery("select USER_TYPE from USERS where USER_NAME = '" + username + "'" + "and USER_PASSWORD = '" + password + "'");
  39.        
  40.             while (rset.next())
  41.             {
  42.                 System.out.println("Login successful!");
  43.                 System.out.println("User Type = " + rset.getString(1));
  44.             }
  45.         } catch (SQLException e) {
  46.             // TODO Auto-generated catch block
  47.             e.printStackTrace();
  48.         }
  49.  
  50.     }
Add Comment
Please, Sign In to add comment