Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

"like" clause not operating properly

843854Feb 20 2002 — edited Apr 30 2004
I am using a very simple prepared statement query with a "like" clause and it is not returning the correct results. I am using JDK 1.3.1_01 and SQLServer (2000 client to a 7.0 DB). The query works fine in Query Analyzer, but returns nothing when I implement in Java. The Java looks like:
---------------------------------------------------------------------
String SQL_GET_METRIC_IDS =
"SELECT m.metric_id " +
"FROM metric m " +
"WHERE m.name LIKE ? " ;

ArrayList metricIdList = new ArrayList();
Connection conn = null;

try
{
conn = DBAccess.getConnection();
PreparedStatement pstmt = StatementFactory.getStatement(conn,
SQL_GET_METRIC_IDS, DebugLevel.ON);

try
{
pstmt.setString(1, metricName);
System.out.println("MUSCMetricBean.getMetricIds(): pstmt=" + pstmt.toString());
ResultSet results = pstmt.executeQuery();
...and so on
------------------------------------------------------------------------
I even print out the Prepared Statement and it displays:
pstmt=SELECT m.metric_id FROM metric m WHERE m.name LIKE 'total fakes'

I realize that I have no wildcard, but there is a record that is exactly 'total fakes'. Also, the reason I am here is that my query using the wildcard wasn't working properly, so I started eliminating variables. This is my desired query:
pstmt=SELECT m.metric_id FROM metric m WHERE m.name LIKE '%total fakes'

Again, neither one of these produces records in Java, but both work fine in Query Analyzer.

Tony
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 28 2004
Added on Feb 20 2002
12 comments
1,503 views