On my program (client - server), sometimes the client send to server a query for example : "select from ....", so on server there is executeQuery, and sometimes the client send to client a query for example : "insert into.... ", so on server there is executeUpdate. I want a method that i can use for executeQuery and executeUpdate.
-
1don't know if there is one, but you can always write your own.Stultuske– Stultuske2014-05-14 09:59:46 +00:00Commented May 14, 2014 at 9:59
-
1So you're sending SQL request string from client to server? Smells like SQL injection.Jk1– Jk12014-05-14 10:31:34 +00:00Commented May 14, 2014 at 10:31
-
It is a project for the university.user3608898– user36088982014-05-14 12:27:00 +00:00Commented May 14, 2014 at 12:27
2 Answers
If you are passing Query String than at Server\Client when you receive the query decide your path.
- Create Different Methods for Execution of different queries and pass parameter as
String(Query) or you can use conditional statements to provide proper execution according to String. - By the use of String Methods like
queryString.startsWith("insert")to find appropriate method for execution and decide whether go forinsert/update/selector anything else.
And yes as user432 has suggested it would be better to go for execute() which can execute any kind of SQL Statement.
But for Queries which returns data you need to use Methods on statement Object Like.
getResultSet()getUpdateCount()
1 Comment
At an API level, this would be a non-sense to have the same method for both, as they do return different objects. The executeUpdate() method returns the number of rows that were affected by your update, whereas the executeQuery() method returns a ResultSet containing all your results, which is very handy.