• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

query problem in jsp

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am running my following query in my jsp page but its goint into catch part & showin unable to connect to database



please help me
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not be doing JDBC in a JSP. Move the code to a Java class where it will be easier to debug.

Moved this to the JDBC forum.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Explain how you are establishing the DB connection. And if that's in a JSP too, then it needs to be moved to a Java class.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks bear for showing your concern actually everything is right except that my role field is integer & logintype is string thats the problem
 
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aditi,

you are showing us the query code and the problem as unable to connect to database.

Please share full code of making the connection and invoking that query.

This will help you and us to resolve this in one go.

Anyways, to resolve that problem, I will straight away run the query on DB console with hard coded values.

If the query runs fine then probably my connection has not established.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you sunny for your reply but as i mentioned above that my connection is allright but instead in my query role is an integer & logintype is a string thats what the problem is


unable to connect database i sshown because i have printed it on the catch part

if you have any solution for that please share it with me

thank you
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please explain, what exactly are you trying to achieve with this query?
 
Ranch Hand
Posts: 544
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,


("select * from ams_menuitems where role is (select logintype from ams_login where loginname= '"+user1.trim()+"');");



Shouldn't the query have "IN" instead of "is" ?

Also subquery will not need the ";" as per my interpreation of the query posted above.

Regards,
Amit
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey swastik actually i have username who is logged in nnow i want on basis of his logintype i should get roles on my jsp page

i cannot change logintype from character to integer as it will effect other forms also

hey amit i have tried is in like = everything but nothing is working
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aditi

You don't have to change the data type in underlying table, but you can always use some conversion function in the query. What database are you using?

 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you all of you for your reply & also sory for wasing your time i have now changed my logintype datatype

its the only solution which i think is remaining
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swastik i am using Postgre SQL
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't worked on this, but your query might go somewhat like this, if you don't wish to change the data type in table.

select * from ams_menuitems where role in (select to_number(logintype,'999') from ams_login where loginname= '"+user1.trim()+"'")

http://www.postgresql.org/docs/7.4/static/functions-formatting.html
 
Aditi agarwal
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i must say swastik you are a genius

you have solved my 2 major problems thank you thank you so much
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to be of some help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic