• Post Reply Bookmark Topic Watch Topic
  • New Topic

can't connect to oracle database in jsp  RSS feed

 
Banchan Sangma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Above is my code :

con is an object of Connection
i keep getting null pointer exception when i try to use the returned connection inside JSP. well i pass con as an argument and call the method, the error appears in the method. But this works perfectly when running it as simple java.

java version 1.8
oracle 11g
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Shouldn't you be getting the JNDI connection rather than using DriverManager.

Also why is "con" returned inside the catch block?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that not enough of a clue that you shouldn't be putting this in a JSP? Java code in a JSP is a huge no-no.

Leave the code in a Java class where it belongs.
 
Banchan Sangma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that code is inside a class. i just call on the method from jsp. and sorry im completely new to all these.
JDBC and JSP. i started jdbc just a month ago and jsp about 2 weeks ago.
And about this particular problem, i got the solution
seems i needed to add this little piece of code to the jsp and it worked

Thanks anyways. Hope to come back with lots of weird/ stupid questions.
Im learning on my own without any teachers so im sure that there'll be lots of it. thanks for Welcoming me :).
 
Banchan Sangma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Is that not enough of a clue that you should/t be putting this in a JSP? Java code in a JSP is a huge no-no.

Leave the code in a Java class where it belongs.


And i still dont know how to write a scriptless JSP as of yet.
Ill learn it after i know how jsp actually works. for now im just mostly going about with what i know of java and what examples i see from the book and the internet
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not the best of ideas, in my opinion. Instilled bad habits are hard to break. I'd learn about JSTL and EL right away, and leave code techniques that have been obsolete for 14 years in the past.

I also recommend novices to JSP read:
  • The Secret Life of JSPs
  • The Front Man

  •  
    Banchan Sangma
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Bear Bibeault wrote:Not the best of ideas, in my opinion. Instilled bad habits are hard to break. I'd learn about JSTL and EL right away, and leave code techniques that have been obsolete for 14 years in the past.

    I also recommend novices to JSP read:
  • The Secret Life of JSPs
  • The Front Man



  • Thank you good sir. I will take your advice. I also believe in doing things the right way.
    But doing things alone, its hard to find what that right way is.
    Its always nice to know that people like you are there to guide people like us in the right path.
    Hope you help me out more in the future too.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!