• Post Reply Bookmark Topic Watch Topic
  • New Topic

Query

 
rose hegde
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i pass a mysql query in jsp? And on event of text field change value of another using the query?
 
JavaHunk
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey rose,
If u r talking about passing a MYSQL query as a request parameter, then
you can always do that, u need to get the value in the JSP from
request parameter and use that as that for querying the DB.
If u r talking about querying DB from JSP directly, that is also
possible the same way as above except u will be having the query in JSP
rather than getting it from request parameter.
In case if u question is related to something else then better
clearly mention what exactly u r looking for.
Regards,
Javahunk
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch JavaHunk!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
Thanks!
bear
JSP Forum Bartender
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rose, while you can pass any text to a JSP (including the text of a SQL query), once it gets to the page, there's not much you can do with it. You cannot, for example, cause it to execute from Javascript as the result of a text field event.
All you would be able to do is to submit a new page (or perhaps resubmit the same page) to cause the query to execute back on the server (in which case passing the query to the first page doesn't make much sense).
Perhaps if you described what you are actually trying to accomplsh, we could come up with a way to achieve it.
bear
 
rose hegde
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me make my Q clear.
I have many fields on my jsp form ..the first 2 being emp no and emp name...so what i want is when i enter emp no in the first field..than on change event of that text field ..i want to call a function where i query the database to get the name of that particular emp no and display in next field.
Pls help...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me make my answer clear: you can't do it that way.
There is no way you can "call a function" as the result of a client-side event to query the database. You will need to initiate a request to the server in order to perform database access.
bear
 
rose hegde
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Than will u pls tell me how to do it?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two basic techniques that you can use:
1) Resubmit the page and fill in the extra information.
2) Submit a request into a hidden iframe, and use the response to generate Javascript that can manipulate your visible page.
bear
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!