i have problem mysql database when try find code can me getting multiple results word "get". find 1 suggestion when search through database. here get
enter word search_______________: get
consider alternative____________: access (e.g. can access of best lawyers)
but have other entries important when comes word "get", , words can fit here alternatives 7. can in java solve problem? have table called grammarchecker, , column named wrongwords, while other 1 rightwords.
how can code in java? have watched videos on hashing dictionary, regular expressions on matching , pattern matching on arrays, regular expressions cannot in java on mysql database. secondly, when comes mysql database, hashing done on text file. possible multiple results word "get" kind of function in java: rs.next()
because don't know how hashing dictionary mysql database possible. want solution.
my problem getting multiple answers mysql database different words through scanner in java. not word get!
i interpret question given user-provided word, want word among wrongwords
in table grammarchecker
, , obtain of associated rightwords
. might this:
list<string> findalternativewords(string userword, connection conn) throws sqlexception { list<string> words = new arraylist<string>(); preparedstatement ps = conn.preparestatement( "select rightwords gammarchecker wrongwords = ?"); try { resultset results; ps.setstring(1, userword); results = ps.executequery(); while (results.next()) { words.add(results.getstring(1)); } } { ps.close(); } return words; }
that assumes have open database connection pass method. note suggest preparedstatement
here, opposed building sql statement directly in string, because user-provided data must handled carefully. otherwise, open (in case) sql injection attack. inserting user's word via prepared statement parameter protects that.
Comments
Post a Comment