I have this code snippet that gives no error or problem at compile time. But when I run the code search button does not search. What is my problem?
JButton btnSearch = new JButton("Search");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0){
try {
String query ="select * from InternTable where InternName like ? OR BirthDate like ? OR"
+ " Comments like ? OR Adress like ? OR InternGSM like ? OR EMail like ? OR "
+ "School like ? OR Project like ? OR Department like ?"
+ "OR Competence1 like ? OR Competence2 like ? OR Competence3 like ? OR"
+ "Competence4 like ? OR Competence5 like ?";
PreparedStatement pst = connection.prepareStatement(query);
pst.setString(1, "%"+tvInternTable.getText()+"%");
pst.setString(2, "%"+tvInternTable.getText()+"%");
pst.setString(3, "%"+tvInternTable.getText()+"%");
pst.setString(4, "%"+tvInternTable.getText()+"%");
pst.setString(5, "%"+tvInternTable.getText()+"%");
pst.setString(6, "%"+tvInternTable.getText()+"%");
pst.setString(7, "%"+tvInternTable.getText()+"%");
pst.setString(8, "%"+tvInternTable.getText()+"%");
pst.setString(9, "%"+tvInternTable.getText()+"%");
pst.setString(10, "%"+tvInternTable.getText()+"%");
pst.setString(11, "%"+tvInternTable.getText()+"%");
pst.setString(12, "%"+tvInternTable.getText()+"%");
pst.setString(13, "%"+tvInternTable.getText()+"%");
pst.setString(14, "%"+tvInternTable.getText()+"%");
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
pst.close();
rs.close();
}
catch (Exception e) {
} } }
);
btnSearch.setBounds(115, 43, 89, 23);
contentPane.add(btnSearch);
Related
The below is the code for the single ID Column search. Can someone help me rewrite this to search other columns in the table please. I need to add LastName, Rank, and EmployerID as searchable as well:
string find = "select * from SDEmployee where (Id like '%' +#Id+ '%')";
SqlCommand cmd = new SqlCommand(find, con);
cmd.Parameters.Add("#Id", SqlDbType.NVarChar).Value = TextBox16.Text;
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "Id");
GridView1.DataSourceID = null;
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
Label1.Text = "Data has been found.";
I tried using the Where, AND OR lines but maybe did not write them correctly. Not sure. I am thinking this might work but need some new eyes in it to check my thinking:
string find = "select * from SDEmployee where (Id like '%' +#Id+ '%' AND 2ndColumn like #var2)";
SqlCommand cmd = new SqlCommand(find, con);
cmd.Parameters.Add("#Id", SqlDbType.NVarChar).Value = TextBox16.Text;
cmd.Parameters.Add(#var2, SqlDbType.NVarChar).Value = TextBoxVar2.Text
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "Id");
GridView1.DataSourceID = null;
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
Label1.Text = "Data has been found.";
i have a big Problem at the moment and i hope anybody know a fix.
on my server i use this code to check vote counts on a website:
#Override
public int getVoteCount()
{
int votes = 0;
try
{
URL oracle = new URL(getLinkToCheck());
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
if (inputLine.contains("<div class='list_8' style=\"font-weight: bold\">"))
{
String line = inputLine.split("<div class='list_8' style=\"font-weight: bold\">")[1].split("</div>")[0].trim().replaceAll(" ", "");
votes = Integer.parseInt(line);
if (VoteManager.VOTE_DEBUG)
{
System.out.println("VoteManager [" + getClass().getSimpleName() + "]: Votes count: [" + votes + "]");
}
return votes;
}
}
in.close();
}
catch (Exception e)
{
System.out.println(e);
}
return votes;
}
every one I m a beginner with Big Data and trying to index and search the data. I have a problem
1)- While indexing program runs very smoothly but while Searching It always shows one or zero hit per query.
Like this:-
Skipped write.lock
Added: D:\Studies\Universities-Punjab University-\Notes\Final Year Project\Appache Lucene\Result 3\file.txt
Added: D:\Studies\Universities-Punjab University-\Notes\Final Year Project\Appache Lucene\Result 3\lab 1.txt
2 Documents Added.
Enter the Search Query (q=quit):
Waleed
Found 1 hits.
D:\Studies\Universities-Punjab University-\Notes\Final Year Project\Appache Lucene\Result 3\file.txt score=0.0390625
Enter the Search Query (q=quit):
Wlaeed
Found 0 hits.
Enter the Search Query (q=quit):
Ahmad
Found 1 hits.
D:\Studies\Universities-Punjab University-\Notes\Final Year Project\Appache Lucene\Result 3\file.txt score=0.0390625
Enter the Search Query (q=quit):
train
Found 1 hits.
D:\Studies\Universities-Punjab University-\Notes\Final Year Project\Appache Lucene\Result 3\lab 1.txt score=0.17900687
Enter the Search Query (q=quit):
q
Code for Indexing:-
Reader fr = null;
try {
Document doc = new Document();
fr = new FileReader(f);
doc.add(new StringField("path", f.getPath(), Field.Store.YES));
doc.add(new StringField("filename", f.getName(),Field.Store.YES));
doc.add(new TextField("contents", fr));
writer.addDocument(doc);
enhanceList(f, helper);
} catch (Exception e) {
System.out.println("Could Not Add: " + f);
} finally {
fr.close();
}
Code for Searching/Querying:-
void searching() throws IOException {
String s = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(directory)));
IndexSearcher searcher = new IndexSearcher(reader);
while (!s.equalsIgnoreCase("q")) {
try {
System.out.println("Enter the Search Query (q=quit):");
s = br.readLine();
if (s.equalsIgnoreCase("q")) {
break;
}
Query q = new QueryParser(Version.LUCENE_44, "contents", analyzer).parse(s);
ScoreDoc[] hits = searcher.search(q, 1000).scoreDocs;
System.out.println("Found " + hits.length + " hits.");
for (int i = 0; i < hits.length; i++) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println((i + 1) + ". " + d.get("path") + " score=" + hits[i].score);
}
} catch (Exception e) {
System.out.println("Error Searching " + s + " : " + e.getMessage());
}
}
}
Please any body help me out in finding out the solution..
I actually followed below link added columns and row data as dynamic, little confused on how to show on xhtml. any help
http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable
List<String> strlist = new ArrayList<String>();
List<List<String>> dynamicListynamicList = new ArrayList<List<String>>();
strlist.add("Name");
strlist.add("SSN");
for(String columnName : columnNamesList){
strlist.add(columnName);
}
List<String> rowData = new ArrayList<String>();
for(String otherList : listData){
try {
rowData.add(otherList.getName());
rowData.add(otherList.getId());
if(otherList.getAmount() != null){
for(BigDecimal amount : otherList.getAmount()){
if(amount != null){
rowData.add(amount.toString());
}else{
rowData.add("");
}
}
}else{
for(String s : strlist){
rowData.add("");
}
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
dynamicListynamicList.add(Arrays.asList(rowData.toArray(new String[rowData.size()] )));
}
String[] strarray = new String[strlist.size()];
dynamicHeaders = strlist.toArray(strarray );
populateDynamicDataTable(dynamicListynamicList);
private void populateDynamicDataTable(List<List<String>> dynamicList2){
HtmlDataTable dynamicDataTable = new HtmlDataTable();
for (int i = 0; i < dynamicList2.get(0).size(); i++) {
HtmlColumn column = new HtmlColumn();
dynamicDataTable.getChildren().add(column);
HtmlOutputText header = new HtmlOutputText();
header.setValue(createValueExpression("#{dynamicItemColumn[" + dynamicHeaders[i] + "]}", String.class));
column.setHeader(header);
HtmlOutputText output = new HtmlOutputText();
output.setValueExpression("value",
createValueExpression("#{dynamicItem[" + i + "]}", String.class));
column.getChildren().add(output);
}
dynamicDataTableGroup = new HtmlPanelGroup();
dynamicDataTableGroup.getChildren().add(dynamicDataTable);
setDynamicList(dynamicList2);
every thing works fine as data being added, now i wasnt sure and my apologies, how to iterate in jsf page(xhtml), to show relvant columna nd rowdata..
I want to read contact details like firstname , lastname, mobile no, telephone , fax, address, synchronization and UID details using PIM apis in Nokia S60 sdk.
But , I am getting only Contact.TEL and Contact.EMAIL value, none of the other values I am getting , although, I am able to see other fields like first name, last name in the emulator contact details.
I have configures all the required permission .
ContactList addressbook = (ContactList) (PIM.getInstance().openPIMList(
PIM.CONTACT_LIST, PIM.READ_ONLY));
Contact contact = null;
Enumeration items = addressbook.items();
while (items.hasMoreElements()) {
String name = "";
String telephone = "";
String mobile = "";
String email = "";
String InternetTelephone = "";
String Company = "";
String JobTitle = "";
String Synchronisation = "";
String UID = "";
String LastModified = "";
String contactRow = "";
System.out.println("\n *** NEW ITEM ***");
contact = (Contact) (items.nextElement());
System.out.println(" * contact : " + contact.toString());
try {
name = contact.getString(Contact.FORMATTED_NAME, 0);
System.out.println("Name = " + name);
} catch (Exception ex) {
System.out.println(" Name error "+ ex.getMessage());
}
try {
mobile = contact.getString(Contact.ATTR_MOBILE, 0);
System.out.println("Name = " + name);
} catch (Exception ex) {
System.out.println(" Name error "+ ex.getMessage());
}
try
{ telephone = contact.getString(Contact.TEL, 0);
System.out.println("Telephone = " + contact.getString(115, 0)); //field 115: Telephone
} catch (Exception ex) {
System.out.println(" Telephone error "+ ex.getMessage());
}
try
{
email = contact.getString(Contact.EMAIL, 0);
System.out.println("E-mail = " + contact.getString(103, 0));
} catch (Exception ex) {
System.out.println(" E-mail error "+ ex.getMessage());
}
try
{
UID = contact.getString(Contact.UID, 0);
System.out.println(" UID " + UID );
} catch (Exception ex) {
System.out.println(" UID error "+ ex.getMessage());
}
try
{
LastModified = contact.getString(114, 0);
System.out.println(" Last modified " + contact.getString(114, 0));
} catch (Exception ex) {
System.out.println(" Last modified error "+ ex.getMessage());
}
looking forward your valuable suggestions.
Thanks in advance.
some sapmles from Nokia .... !
http://www.developer.nokia.com/Community/Wiki/How_to_read_contacts_using_JSR_75