File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Jsp connection to MySql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp connection to MySql" Watch "Jsp connection to MySql" New topic
Author

Jsp connection to MySql

chure abcede
Greenhorn

Joined: May 31, 2013
Posts: 14
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

Joined: Jan 10, 2002
Posts: 60975
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
chure abcede
Greenhorn

Joined: May 31, 2013
Posts: 14
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

Joined: Jan 10, 2002
Posts: 60975
    
  65

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

Joined: May 31, 2013
Posts: 14
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

Joined: May 31, 2013
Posts: 14
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

Joined: Jan 10, 2002
Posts: 60975
    
  65

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

Joined: May 31, 2013
Posts: 14
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

Joined: Jan 10, 2002
Posts: 60975
    
  65

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jsp connection to MySql