troubleshooting Question

query database through list

Avatar of perdoname_
perdoname_ asked on
JavaMySQL Server
2 Comments2 Solutions170 ViewsLast Modified:
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
 
 
};
ASKER CERTIFIED SOLUTION
JesterToo

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros