Link to home
Start Free TrialLog in
Avatar of perdoname_
perdoname_

asked on

query database through list

Hello Experts,


I need your assistance how can I use the list created in the EmployeeNameSearch() method to search in the database which of the names given are not in the database

Thanks in advance for any assistance !
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
 
public class createTable 
{
	public static void main(String[] args) 
	{
		DB db = new DB();
		Connection conn=db.dbConnect(
				"jdbc:qed:mynewdb://localhost:1925", "p");
		db.createTables(conn);
	}
}//createTable
 
class DB
{
	public DB() {}
 
	public Connection dbConnect(String db_connect_string,
			String db_userid)
	{
		try
		{
			Class.forName("com.quadcap.jdbc.JdbcDriver");
			java.util.Properties p = new java.util.Properties();
			p.setProperty("create", "true");
			java.sql.Connection conn =
				java.sql.DriverManager.getConnection("jdbc:qed:mynewdb", p);
			return conn;
 
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return null;
		}
	} //Connection dbConnect
 
 
	//Employee table
	public void createTables(Connection conn)
	{
 
		String query;
		Statement stmt;
 
		try
		{
			query="create table cust_profile " +
			"(name varchar(32), " +
			"id varchar(50), " +
			"telephoneNo varchar(50), " +
			"email varchar(50))";
			stmt = conn.createStatement();
			stmt.executeUpdate(query);
			stmt.close();
			conn.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	} //createTables
 
 
 
	public void createJobRoles(Connection conn)
	{
 
		String query;
		Statement stmt;
 
		try
		{
			query="create table Job_roles " +
			"(JOB_ID INTEGER NOT NULL, " +
			"job_title varchar(32), " +
			"salary_class varchar(50), " +
			"job_description varchar(50), " +;
			"primary key(JOB_ID))";
			stmt = conn.createStatement();
			stmt.executeUpdate(query);
			stmt.close();
			conn.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
 
	public void EmployeeNameSearch(Object args) {
 
		List names =  Arrays.asList(args);
 
		Collections.sort(names); //sort ArrayList required for binarySearch
 
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String option = stdin.readLine();
 
			if (cust_profile.binarySearch(names.toArray(),option.toLowerCase())== -1)
			{	
				System.out.println("Not found in database: ");
				System.out.println("Name: " + option );
 
			}
 
		}
 
 
	}; //namesSearch
 
 
};

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JesterToo
JesterToo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial