Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Connecting to MySQL

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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: 25815
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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: 25815
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
I'm full of tinier men! And a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic