• 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

Connecting to MySQL

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I just starting off using JSP and I was wondering if someone could help me. I am trying to connect to a database called test and retrieve information from the clubname column in the clubs table. Can anyone help as I am at my witts end.

Thanks a Million

Colm
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Colm O'donnell,
Welcome to JavaRanch.

Well, connecting to database from JSP is not a good practice and is kind of forbidden. Please do not use JSP to connect to database. Pass data to a servlet for validation, or use JavaScript to valildate them in JSP, and setup connection inside servlet and then as required go back to previous page to get correct/new data or move on to the next page.

Well, a bad practice code to connect database on a JSP page can be foundat this link.
[ April 08, 2008: Message edited by: Anubhav Anand ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
colm,
Maybe, if you give us a little more to work with, we can get you up and running. What have you tried so far? What container are you using?
What does your code/configuration look like?
 
colm o'donnell
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As i said I am kinda new at this. I am doing a comparison between JSP and PHP and I am building 2 simple website that access mysql. I don't really know much about JSP although I know PHP. I am using Netbeans to make the application. I have MySQL installed on the computer will Netbeans be able to access that??

Thanks again

Colm
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One important distinction.

Netbeans is an IDE (Integrated development environment), not a container.
Netbeans has an embedded version of Tomcat inside it and yes you can certainly connect to a MySql database with it.

My personal recommendation is that you put the IDE aside while learning JSP and servlets. Once you can install and configure Tomcat (or any other spec compliant container), write, compile, and deploy an app with a text editor, and command line compiler, then, shop around to see if any of the available IDEs will speed up development for you.

If you wish to continue learning with Netbeans, let me know and I'll move this to our IDEs forum where someone should be able to point you in the right direction for getting a connection to Mysql. If not, let me know and I'll move this to our Apache Tomcat forum for you.
In either case, we should be able to get you up and running in a short amount of time.
 
colm o'donnell
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought the same but its a project for college and they want me to do it in netbeans so I'm going to have to stay with that i'm afraid

thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a problem.

Since the embedded version of Tomcat that Netbeans uses has been altered to work in the IDE, this question will do better in our IDEs forum.
Moving for you.

-Ben
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
this question will do better in our IDEs forum.

Well, you connect to a database in Netbeans exactly the same way you do in Eclipse, and exactly the same way you would do if you were using Notepad to create your JSP. It's really a JDBC question. But it would be cruel to move it yet again, so I will let it languish here.

Have a look on the Internet for JDBC tutorials, though.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
Well, you connect to a database in Netbeans exactly the same way you do in Eclipse, and exactly the same way you would do if you were using Notepad to create your JSP.



Not necessarily.
Web containers (Tomcat anyway) look for classes in a specific set of directories instead of from the classpath environment variable.
In a standalone install of Tomcat, the drivers libs need to go in one of a few possible directories (this is more specific if you're using container managed connection pooling). If he were using Tomcat as a standalone, I could have helped him with this. Netbeans uses an embedded version of Tomcat and, since I'm not sure how you set up a web development environment in Netbeans, so... I sent it here hoping that someone who's done this before can point him in the right direction.
[ April 08, 2008: Message edited by: Ben Souther ]
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you're assuming it's a classpath problem? I guess that's as good a guess as any, given the level of detail in the original post.
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic