SQL query returns no result from Java although it returns a result in Access -
when run query:
select character tbl_unknown format(fw,'.###')='48.143' , code='0001'
it returns result in access query interface when try run java doesn't return result.
my table (tbl_unknown):
char_id: autonumber value:1 fw: short text value:'48.1425' hint:after format become '48.143'. code: short text value:'0001' character: short text value: 'x'
my java code:
public static string getlostedcharacter(string font,string fw, string code) { connection conn = connectdb.getconnection(); string character = null; try { statement statement = conn.createstatement(); string query = "select character tbl_"+font+" format(fw,'.###')='"+fw+"' , code='" + code + "'"; resultset rs = statement.executequery(query); while (rs.next()) { character = rs.getstring(1); return character; } statement.close(); rs.close(); } catch (sqlexception ex) { return ""; } return ""; }
access sql queries run from within access application itself can use wide variety of vba functions may not available (or may behave bit differently) in access sql queries run other applications.
as workaround, suggest this:
string query = string.format( "select character tbl_%s " + "where trunc((val(fw)*1000)+0.5)=? , code=?", font); preparedstatement ps = conn.preparestatement(query); ps.setint(1, (int)(1000 * double.parsedouble(fw))); // e.g. 48143 ps.setstring(2, code); resultset rs = ps.executequery();
edit re: comments
as explained jamadei, format()
function implemented in ucanaccess versions <= 2.0.6.2 produces different results access/vba implementation particular case. format(48.1425,".###)
returns 48.143
in access query returns 48.142
in ucanaccess query. this may corrected in future release of ucanaccess. has been corrected in ucanaccess 2.0.6.3.
Comments
Post a Comment