Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

J2ME connecting database in Server using Servlet

 
Arya Quskhan Shah
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Helloo,
I am new user here.I have develope some client/server by using midlet and servlet. The midlet run well but I have the problem with servlet.
While I run the midlet from Ktoolbar, it display HTML code with messge Error 500 that SQL error.
So i suggest there are some problem in execution SQL servlet.
Please advice anyone to solve this problem...

Here are the code of servlet :


[ May 06, 2006: Message edited by: Mark Spritzler ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, we have these great CODE tags that will keep your code formatted. Under the Add Reply Button is a set of 10 buttons to do cool stuff. One of them is the CODE tag.

So for you problem, what happened is a very very very common problem, one which I do all the time.

rs=st.executeQuery("SELECT status,datePO,shipdate"+
"FROM orders"+"WHERE ordernumber='"+
orderNumber +"'");

You are concatinating strings here, but between some of them there is no extra space. so your final string is

"SELECT status,datePO,shipdateFROM orderWHERE ordernumber='(whatever orderNumber values is here)'"

So between your shipdate and FROM clause there is no space, and between your order and WHERE clause there is no space.

Now the following will work

rs=st.executeQuery("SELECT status, datePO, shipdate"+
" FROM orders"+" WHERE ordernumber='"+
orderNumber +"'");
 
Arya Quskhan Shah
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Thanks for your advice..I'll check and try it immediately.
Hopefully it can work as good as you said.
Anyway..thanks a lot..

Regards,
Arya
 
Arya Quskhan Shah
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i already try as you said..n it didnt work. There is strill error n cannot execute the SQL.
On network monitor display as follow :

request ---> GET/Final/status?orderNumber=2004012 HTTP/1.1
response---> HTTP/1.1 500 Internal Server Error

So I change the command as " SELECT status,datePO,shipdate FROM order WHERE ordernumber='2004012'". (with space on shipdate-FROM and order-WHERE)
On network monitor display as follow:
request ---> GET/Final/status?orderNumber=2004012 HTTP/1.1
response---> HTTP/1.1 200 OK

It looks like fine right. But when it goes to the code


there is always throw to the 'else ' and forward to statusfailed.jsp whatever it value of orderNumber.
So i suggest resultSet rs cannot execute the SQL code.

here is the code for status.jsp and statusfailed.jsp
status.jsp


statusfailed.jsp


Please your immediately response everyone..
Thanks a lot

Regards,
Arya
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"So I change the command as ..."

Um, I don't see a difference between what I said and what you just typed.

Anyway, it looks like you are getting the query to run, but the resultsSet is now the issue. And if it is going to the else statement, then the resultSet is empty. Have your tried running your query through some SQL tool like Toad, or SQL Plus to run your query to see if it actually would have values returned.

Thanks

Mark
 
Arya Quskhan Shah
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyway...I already check it with the SQL editor..it's OK nothing problem.
When i execute your SQL code its error. So it's differ with the one.
already try with preparedStatement..I wish it can help.But i got same result.
Is there any chance to solve this Mark..

Regards,
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arya Quskhan Shah:
Anyway...I already check it with the SQL editor..it's OK nothing problem.
When i execute your SQL code its error. So it's differ with the one.
already try with preparedStatement..I wish it can help.But i got same result.
Is there any chance to solve this Mark..

Regards,


rs=st.executeQuery("SELECT status, datePO, shipdate"+
" FROM orders"+" WHERE ordernumber='"+
orderNumber +"'");


Still very confused, the only different between yours and mine is that I don't put an exact ordernumber in mine, because your code wanted to assing that part of the query based on the value of a variable. Other than that, they are identical. Unless you tried to used the word "orderNumber" or the String "(whatever orderNumber values is here)" which is wrong because I put that because I don't know the values or your ordernumbers.


Using a statement or a prepared statement won't make the difference. The issue is the String query that is running and the results you get back from the query string. How many records come back in the SQL Editor when you run your query?

rs.next() will return false if there are no more records, or no records to begin with.

Mark
 
Arya Quskhan Shah
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike..
You know Mike,actually there is no problem with SQL command,but I don't know when 4 days ago I try one by one by input each step including giving value to orderNumber there are no problem. So i found out that one of big problem are in getParameter. when i re-type servlet code. It can works well...very well .
Gosh..its strange situation for me.So the case is close.
Thanks for your help Mark. Its valuable for me a lot.
Anyway do you have a code for servlet which can update database by using executeUpdate() ?? because when i use above code..it cant work..So i open new case for you Mark hehe...

--Arya---
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could always either have a seperate Servlet for updates, or you can have a variable in the Request that you set to the type of query you want to run, and then in your code, check that value and change the string for the SQL Statement to execute a different query.

"UPDATE orders FIELDS(status, datePO, shipdate) VALUES("SomeStatus", '10/1/2006', '10/2/2006') WHERE ordernumber= 'someOrderNumber'"



Mark
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic