0

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.

3
  • 1
    don't know if there is one, but you can always write your own. Commented May 14, 2014 at 9:59
  • 1
    So you're sending SQL request string from client to server? Smells like SQL injection. Commented May 14, 2014 at 10:31
  • It is a project for the university. Commented May 14, 2014 at 12:27

2 Answers 2

1

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 for insert/update/select or 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()

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I used the method that user432 has suggested, work! thank you anyway.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.