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
};
Select all Open in new window