Hi I have written the following code. After execution when I give inpt from command line it does not do anything. Please tell me is there anything wrong in code.
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.
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.
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..
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..
Bharath, 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.
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.
Sir, what should I do in this case, because my requirement is to give queries at runtime whether it may be select, insert, update, etc.
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?
Yes, you are right, it is waiting for me to give an input. After giving input for e.g.:"select * from emp" and pressing enter it does nothing. That's what I mean by "doing nothing". Only one thing it does is exit.
Please suggest me what to do.
Bharath Raja
Ranch Hand
Joined: Jan 21, 2009
Posts: 111
posted
0
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.
what "mohamed sanaullah" said is exactly right.. so how you expected empty prepared statement give you the result.. you should try the following code...
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.
Bharath Raja
Ranch Hand
Joined: Jan 21, 2009
Posts: 111
posted
0
oops .. sorry .. there is correction in my previous post...
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
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.
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.
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.
As said by Christophe, please go through the JDBC tutorial. And it should work for parametrized/non-parametrized SQL.
Christophe Verré wrote:You have to use anotherResultSet.
Sir, can you please explain me?
Prince Sewani
Ranch Hand
Joined: Nov 24, 2010
Posts: 32
posted
0
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.
Alright i don't know what they're mentioning about two result-sets but to me it comes like this:
Yeah as 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"
So according to me it should be more like : -
Now as per the parameterized part,that's something which asks for the analysis of what exactly are you gonna provide to the user,
1. is it gonna be and live query browser? -then you don't have to worry about parameters
2. if you're gonna provide a GUI that's gonna work both the ways that is like a query browser and as well as an interactive version which asks for few values
and based on them it does the rest of the operations then it will be better to define stored procedures in database and use them from your code based on some event like a radio button and all and then using :-
For that you gotta go to the JDBC tutorial..
regards
Prince Sewani
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.