Re: Using the WHERE clause in a ResultSet
Myself and another person have given you very good explanations about how to do this. Either you're ignoring those for some reason or this is really beyond your capability. You should consider hiring a professional. Sent from my iPad > On Nov 3, 2015, at 11:43 PM, Bob Mwrote: > > string1 thru string4 are VARCHAR variables > > In my particular case each of the strings can be either"Up" or "Down" but > their values vary each time my program runs which is every 6 > hours.. > > Sorry for being a bit slow, but I am still unclear as to how to ask for a > subset of the table where Fields 1 thru 4 have as their values string1 thru > 4 > > > > -- > View this message in context: > http://apache-database.10148.n7.nabble.com/Using-the-WHERE-clause-in-a-ResultSet-tp144994p145000.html > Sent from the Apache Derby Users mailing list archive at Nabble.com. >
Re: Using the WHERE clause in a ResultSet
If you're using JDBC, you would use a prepared statement. This isn't exact, but something like: PreparedStatement ps=conn.prepareStatement("select * from table where field1=? and field2=?"); ps.setString(1,variable1); ps.setString(2,variable2); ResultSet rs=ps.executeQuery(); while (rs.next()) { } On 11/3/2015 10:17 AM, Bob M wrote: I wish to use the WHERE clause as follows:- Field 1 = current value of variable 1 Field 2 = current value of variable 2 etc. when I use code such as WHERE Field1 = variable1 AND Field2 = variable2 I get an error message saying that variable1 is not in any table in FROM list. How do I correct this? -- View this message in context: http://apache-database.10148.n7.nabble.com/Using-the-WHERE-clause-in-a-ResultSet-tp144994.html Sent from the Apache Derby Users mailing list archive at Nabble.com. -- George Sexton *MH Software, Inc.* Voice: 303 438 9585 http://www.mhsoftware.com
Re: Using the WHERE clause in a ResultSet
I am using the following code:- rs = s.executeQuery("SELECT Field1, Field2, Field3, Field4 FROM XX " + "WHERE Field1 LIKE String1 AND Field2 LIKE String2 AND Field3 LIKE String3 AND Field4 LIKE String4 " + "GROUP BY Field1, Field2, Field3, Field4"); XX - table name Field1 thru Field4 are VARCHAR variables and am getting the error on String1 -- View this message in context: http://apache-database.10148.n7.nabble.com/Using-the-WHERE-clause-in-a-ResultSet-tp144994p144997.html Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: Using the WHERE clause in a ResultSet
On 11/3/2015 3:35 PM, Bob M wrote: I am using the following code:- rs = s.executeQuery("SELECT Field1, Field2, Field3, Field4 FROM XX " + "WHERE Field1 LIKE String1 AND Field2 LIKE String2 AND Field3 LIKE String3 AND Field4 LIKE String4 " + "GROUP BY Field1, Field2, Field3, Field4"); XX - table name Field1 thru Field4 are VARCHAR variables and am getting the error on String1 If String1 is a literal string constant, for example WHERE Field1 like California% then you want to put your literal string constant in single quotes, as in: WHERE Field1 like 'California%' or use PreparedStatement substitution, as in: WHERE Field1 like ? ps.SetString( 1, 'California%' ); bryan
Re: Using the WHERE clause in a ResultSet
string1 thru string4 are VARCHAR variables In my particular case each of the strings can be either"Up" or "Down" but their values vary each time my program runs which is every 6 hours.. Sorry for being a bit slow, but I am still unclear as to how to ask for a subset of the table where Fields 1 thru 4 have as their values string1 thru 4 -- View this message in context: http://apache-database.10148.n7.nabble.com/Using-the-WHERE-clause-in-a-ResultSet-tp144994p145000.html Sent from the Apache Derby Users mailing list archive at Nabble.com.