I have a database in which i have 3 columns (id, name, info_link).
I have the id and names stored in the database.
I have a text file where i have all the info links scraped.
Info link is in the form of : http://someURL/**Name**.htm
Now what I want to do is Take a name from the database, read a line from the text file of links, find if the link(line) contains that drug name, put that link in the info_link column of the record.
This is what my code is
BufferedReader reader = new BufferedReader(new FileReader("./Links.txt"));
BufferedWriter writer = new BufferedWriter(new FileWriter("./AddedLinks.txt"));
int id = 1;
//Creates a connection to the Database
connection = DriverManager.getConnection(DB_URL,DB_USER,DB_PASS);
statement = connection.createStatement();
for(id=1;id<=1153;)
{
query = statement.executeQuery("SELECT name FROM drug_list WHERE id = '"+id+"';");
query.next();
String name = query.getString(1);
String words[] = name.split(" ");
String Myvalue = reader.readLine();
boolean Found = false;
while(!Found)
if(Myvalue.toLowerCase().contains(words[0].toLowerCase()))
{
Boolean f = false;
System.out.println("Found"+name);
update = connection.prepareStatement("UPDATE drug_list SET info_link = ? WHERE id = ?;");
update.setString(1, Myvalue);
update.setInt(2, id);
f = update.execute();
if(!f)
{
System.out.println("QSE");
id++;
writer.write(Myvalue);
Found = true;
}
}
else
{
System.out.println("Could Not Find"+name+"\n");
id++;
Found = false;
}
}
I am able to match the container links that have to be processed on Single Words. But the problem is
I have a drug names like
- Albuterol (Salbutamol)
- Dorzolamide/Timolol
etc..
And Their Corresponding Links like :
- http://Somelink/**albuterol_salbutamol**.htm
- http://Somelink/**dorzolamide_timolol**.htm
Also there are a few Names in the Database that do not have a corresponding link in the text file, i also want to skip those. I have 1153 Values in total in my database.
Also I have a few drug names like
- Calcium Something
- Calcium Something Something
- Calcium Not Something
So this creates a problem IF i am matching just the word[0] that i split up. Because it will update all the values for Calcium Something Field Only.
You use a regex to split the words. Something like
and iterate over and check all the words instead of just one word.