Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void searchCustomer(){
- Scanner scan = new Scanner(System.in);
- String type="";
- String name="";
- System.out.println("Search Customer");
- System.out.print("[B]usiness or [I]ndividual ");
- type = scan.nextLine();
- if(type.equals("B") || type.equals("b")){
- System.out.print("Customer Name : ");
- name = scan.nextLine();
- try{
- Statement statement = DriverManager.getConnection("jdbc:mysql://localhost/javaday2?user=root&password=").createStatement();
- String q =
- "SELECT business.NAME, customer.ADDRESS, customer.CITY from customer INNER JOIN business ON customer.CUST_ID=business.CUST_ID WHERE NAME='"+name+"'";
- ResultSet rs = statement.executeQuery(q);
- while(rs.next()){
- String row="";
- row = rs.getString(1) +" \t| "+ rs.getString(2) + "\t\t| " + rs.getString(3);
- System.out.println(row);
- }
- rs.close();
- statement.close();
- }catch(SQLException e){
- System.out.println("SQLException: " + e.getMessage());
- System.out.println("SQLState: " + e.getSQLState());
- System.out.println("VendorError: " + e.getErrorCode());
- }
- }
- else if(type.equals("I")||type.equals("i")){
- System.out.print("Individual Name : ");
- name = scan.nextLine();
- try{
- Statement statement = DriverManager.getConnection("jdbc:mysql://localhost/javaday2?user=root&password=").createStatement();
- String q =
- "SELECT individual.FIRST_NAME, customer.ADDRESS, customer.CITY from customer INNER JOIN individual ON customer.CUST_ID=individual.CUST_ID WHERE FIRST_NAME='"+name+"'";
- ResultSet rs = statement.executeQuery(q);
- while(rs.next()){
- String row="";
- row = rs.getString(1) +" \t| "+ rs.getString(2) + "\t\t| " + rs.getString(3);
- System.out.println(row);
- }
- rs.close();
- statement.close();
- }catch(SQLException e){
- System.out.println("SQLException: " + e.getMessage());
- System.out.println("SQLState: " + e.getSQLState());
- System.out.println("VendorError: " + e.getErrorCode());
- }
- }
- else{
- System.out.println("WRONG INPUT !");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement