Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using java for searching for data by using part of the row in microsoft access database

I have this table

enter image description here

And I am using the following code to retrieve data from my table that returns all the English words that its Kurdish word contains بةرز

targetText="بةرز";
try (PreparedStatement ps = conn.prepareStatement(
"SELECT English,Kurdish FROM Info " +
"WHERE Kurdish = ? " +
"OR REGEXP_MATCHES(Kurdish, ?) " +
"OR REGEXP_MATCHES(Kurdish, ?) " +
"OR REGEXP_MATCHES(Kurdish, ?) ")) {
   ps.setString(1, targetText);
   ps.setString(2, "^[. ]*" + targetText+ "[ ]*[:،,]+[ .]*$");
   ps.setString(3, "^[. ]*[:،,]+[ ]*" + targetText+ "[. ]*$");
   ps.setString(4, "^[. ]*[:،,]+[ ]*" + targetText+ "[ ]*[:،,]+[  .]*$");
   try (ResultSet rSet = ps.executeQuery()) {
      while (rSet.next()) {
         System.out.println(rSet.getString("English"));
         System.out.println(rSet.getString("Kurdish"));
      }
   }
}

So it works fine, it prints all the English words that I want.
My problem is that when I get the corresponded Kurdish word it doesn't print the complete cell. It just prints بةرز,

For example the output of the previous code should be:

aesthete
بةرز ، جوانىثةرست
aether
زوَر ناسك ، بةرز ، ثيروَز ، ئاسمانى
affair
بةرز 

But it prints

aesthete
بةرز 
aether
بةرز 
affair
بةرز 

What can I do to get the output that I want?

Note that I am using UCanAccess for my database connection,

like image 534
Hamreen Ahmad Avatar asked Oct 23 '15 15:10

Hamreen Ahmad


People also ask

How do I select a specific row in an Access query?

You can go to a specific record in Access when you know which record you want to find. The Go to box lets you choose a particular record from a drop-down list and is usually added to forms. To navigate to a specific record, click the arrow to the right of the Go to box, and then select a record from the drop-down list.

How do you search for data in Microsoft Access?

On the Home tab, in the Find group, click Find. The Find and Replace dialog box appears, with the Find tab selected. In the Find What box, type the value for which you want to search. To change the field that you want to search or to search the entire underlying table, click the appropriate option in the Look In list.

How do I extract specific data from Access?

To export data from Access, first select the table or other database object to export in the Navigation Pane. Then click the “External Data” tab in the Ribbon. Then click the button in the “Export” button group for the file format to which to export the object.

How do you filter by selection in Access?

Another way to access the selection filter options is to right-click the specific cell. For example, if the value 2/21/1967 is currently selected in the BirthDate field, on the Home tab, in the Sort & Filter group, click Selection to display the filter by selection commands, and then select your filtering option..


1 Answers

Tanks for all, I have solved it just with a few change within the regx

targetText="بةرز";
try (PreparedStatement ps = conn.prepareStatement(
   "SELECT English,Kurdish FROM Info " +
   "WHERE Kurdish = ? " +
   "OR REGEXP_MATCHES(Kurdish, ?) " +
   "OR REGEXP_MATCHES(Kurdish, ?) " +
   "OR REGEXP_MATCHES(Kurdish, ?) ")) {
   ps.setString(1, targetText);
   ps.setString(2, "^" + targetText+ "[ ]*(،)[.]*");
   ps.setString(3, "[.]*(،)[ ]*" + targetText+ "$");
   ps.setString(4, "[.]*(،)[ ]*" + targetText+ "[ ]*(،)[.]*");
   try (ResultSet rSet = ps.executeQuery()) {
      while (rSet.next()) {
         System.out.println(rSet.getString("English"));
         System.out.println(rSet.getString("Kurdish"));
      }
   }
}
like image 184
Hamreen Ahmad Avatar answered Oct 29 '22 11:10

Hamreen Ahmad