//---------------------------------------------------------------------
//eCare.java
//queries database for user information
// retrieves information if valid user
//input: user_ip_address. pin
//output: info pertaining to minutes of use and bill info.
//-------------------------------------------------------------------

import java.sql.*;
import java.math.*;
import java.io.*;

class eCare
{
  public static void main (String args [])
       throws SQLException, ClassNotFoundException
  {
	// first argument from input is args[0]
	String subIPaddr = args[0];
	String subPIN=args[1];
	String subRec = "";

    // Load the Oracle JDBC driver
	DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ());
Connection conn=DriverManager.getConnection ("jdbc:oracle:thin:lalitha/vaishu@sai:1521:CNS");

    // Create a Statement
    Statement stmt = conn.createStatement ();

//    String query = "select last_bill_date, amount_due, min_used, min_left from billinfo where mobil_pin = '" + subPIN + "'";
    String query = "select last_bill_date, amount_due, min_used, min_left from billinfo where ip_addr = '" + subIPaddr +"' and mobil_pin = '" + subPIN + "'";

	ResultSet rset = stmt.executeQuery (query); 
    int columns = (rset.getMetaData()).getColumnCount();
if (!(rset.next())) {
		subRec = "invalid login";
	System.out.println(subRec);
	} 
else {
        // Dump the result
        for (int pos = 1; pos<= columns; pos++) {
           subRec=((rset.getMetaData()).getColumnName(pos) + ": "+ rset.getString(pos) + "\n ");
	System.out.println(subRec);
        }
	
	System.out.println("IP_ADDR: " + subIPaddr + "\n PIN: " + subPIN);
}

  }
}
