0

I have successfully used the csvjdbc1.0-35 for all of my database retrieval requirements with the exception of the where fieldName Like value% clause. I am connecting to a file system as served via http. Below is my connection sequence

selectPhrase = "Select Amount ";
fromPhrase = " From http://10.31.46.143:8080/Extracts/20210331/DataSet ";
wherePhrase = " Where criteriaField Like '1%'";
sqlStmt = selectPhrase + fromPhrase + wherePhrase;                                           
Class.forName("org.relique.jdbc.csv.CsvDriver");
Connection conn = DriverManager.getConnection("jdbc:relique:csv:class:" +
                  MyHTTPReader.class.getName());
Statement stmt = conn.createStatement();                         
ResultSet results = stmt.executeQuery(sqlStmt);
while (results.next()) {
   String amtS = results.getString(1);
}

I have not had any issues with any other wherePhrases' (eg: criteriaField = '10', criteriaField <> '15', etc) but when I use the wherePhrase = "criteriaField Like '1%'", results executes but returns as empty. My csv file is approximately 250K records

  • 1
    `criteriaField` is probably interpreted as numerical, https://stackoverflow.com/questions/31163728/csvjdbc-interpreting-strings-instead-of-integers-in-aggregate-functions – Joop Eggen Jun 14 '21 at 19:13
  • Can you show some sample data which causes this behavior? When I test with simple numeric data values such as `123` and `234`, then your syntax works as expected: `field like '1%'` finds `123` but not `234`. – andrewJames Jun 14 '21 at 20:16
  • 1
    there is a second criteria field that I did not list in the original post as to not muddle the issue. The second criteria was a hard value with a leading zero (no LIKE clause required) After reviewing the data carefully, I noticed that at some point while opening and reopening the source csv file in excel, the leading zero had been stripped off of the 2nd criteria field. There was never an issue with the LIKE clause, just spent the day on the wrong thing! – user16225638 Jun 14 '21 at 22:19
  • I think this is one reason why providing a [mre] for SO questions is mentioned so often: In the course of putting one together, you solve the problem (ideally before needing to ask the question). Anyway - you solved it - and that's great! – andrewJames Jun 14 '21 at 22:23

0 Answers0