Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Life is either daring something or nothing - Helen Keller
Bharath Raja wrote:please check your code.. you have added the null query to prepared statement.. let us see that...
initially your query string is empty .. so that it would do nothing for you.. you should put your query string(after reading from user) to prepared statement..
mohamed sanaullah wrote:Create an instance of the PreparedStatement after you have taken input for query. You have provided an empty string as the query, which the PreparedStatment is using it. You taking of input from the command line for the query isnt changing the query in the PreparedStatement.
Paul Clapham wrote:As I understand it, the first thing it would do would be to wait for you to input data. This might appear to be "doing nothing" to somebody who hadn't been told they had to provide input.
Or perhaps "doing nothing" means something else?
execute() is for executing any type of sql statements whether it select or non-select. At runtime, if you don't know what type of query is the client going to give, then which behavior will you use. Moreover, if the client gives exit instead of giving any query then what happens. That's why, I have used empty string.
Life is either daring something or nothing - Helen Keller
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Bharath Raja wrote:
How can you write this type of code, as prepared statement object is instantiated and intialized by connection object and for that prepareStatement() method is defined in the connection interface and this method takes input as SQL statement which is nothing but string in java.
NitishK Kumar wrote:
How can you write this type of code, as prepared statement object is instantiated and intialized by connection object and for that prepareStatement() method is defined in the connection interface
Life is either daring something or nothing - Helen Keller
Christophe Verré wrote:
And what happens when you enter "exit" ?
Life is either daring something or nothing - Helen Keller
mohamed sanaullah wrote:So the flow would be:
Ask the user for the Query Input Take the input Create PreparedStatement instance using the above query
[My Blog]
All roads lead to JavaRanch
mohamed sanaullah wrote:So the flow would be:
Ask the user for the Query Input Take the input Create PreparedStatement instance using the above query
NitishK Kumar wrote:thank you sir, one more problem I have when I am giving when I am giving non-parameterized SQL statement, it works fine but for parameterized SQL statements, its not working.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Bharath Raja wrote:
his logic is actually wrong... he have to write the while loop after reading input from user right.
NitishK Kumar wrote:
Bharath Raja wrote:
his logic is actually wrong... he have to write the while loop after reading input from user right.
You mean to say that I should first take query from the user and then should go for checking whether it is equal to exit or not. Am I right?
Regards
Prince
---------------------------------------------------------
SCJP 6 , still a life long learner
Prince Sewani wrote:
Yes Nitish,that's the way it will work.
Christophe Verré wrote:You have to use another ResultSet.
NitishK Kumar wrote:
Prince Sewani wrote:
Yes Nitish,that's the way it will work.
But, when I did so, the resultset loop started executing infinite loop.
Regards
Prince
---------------------------------------------------------
SCJP 6 , still a life long learner
Consider Paul's rocket mass heater. |