Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jsp connection to MySql

 
chure abcede
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I need your help, I just really don't know how to connect my jsp into mysql.., I tried this code:



I get this code from my connection when using java alone. Also I saw this code in net and I just revise it. I dont know if it connects to the mysql.. when I try to run it theres nothing on the screen like Successfully connected or error message.



Thanks guys,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not code that should be in your JSP. In fact, there should be no code in your JSP.

Move the code to a class in the model layer.
 
chure abcede
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sir,

Now im confused again, so what should I code in JSP?, and where should my code like db connection and methods be placed ?
One more sir, is JSP similar to HTML but it is run under JVM?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more sir, is JSP similar to HTML but it is run under JVM?

No, JSP produces HTML. To understand what JSP is, please read this article.

chure abcede wrote:Now im confused again, so what should I code in JSP?

Nothing. Putting Java code into a JSP has been obsolete for 12 years. Please see this JspFaq entry.

and where should my code like db connection and methods be placed ?

In the model classes. Please see this article for information on properly structuring web applications.

I sounds as if you need to read some books or tutorials to understand the basics of programming web applications. Be sure that the JSP resource focuses on JSTL and EL, and not on obsolete Java scriptlets.
 
chure abcede
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't yet have over view in website development, i just started in web application from desktop application. Do you have any recommended books or pdf file that should I read that is best suited for beginners because some of the tutorials are advance?
 
chure abcede
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was so lucky that i read your post about not using scriplets, because i had just used it a while ago in connecting to data base and its been obsolete.., thanks sir..,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chure abcede wrote:I don't yet have over view in website development, i just started in web application from desktop application. Do you have any recommended books or pdf file that should I read that is best suited for beginners because some of the tutorials are advance?

Head First Servlets and JSP is often recommended. (Disclaimer: I was a tech reviewer of this book.)
 
chure abcede
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help sir, I already tried using a .java file into a jsp and it works well. But I have a little problem,I want to print a message in the html like hellow world but it only printed in the console of eclipse since im using S.O.P.

I tried to use the servlet but i'm having an error. java.lang.NullPointerException


my JSP

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop putting Java code in your JSP. Even if you can get it to work, it's a poor and obsolete practice.

Of course you can't just plop a method into servlet -- or any other class -- and call it from a JSP expecting it to magically have a response. That's not how servlets work.

This is the sort of dangerous thinking that putting Java code into a JSP results in.

If you want a message to appear in the HTML it should be create in the JSP, either with HTML markup or with JavaScript.

Again, I think you are in a deep hole and digging yourself deeper. You need to back up a bit and understand some of the fundamentals of how the web works before diving off into whatever it is you are doing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic