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

JavaMySQL Server

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
JesterToo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes