jsp with mysql connection

Reply

Join Date: Jan 2007
Posts: 15
Reputation: jeet_portal is an unknown quantity at this point 
Solved Threads: 0
jeet_portal jeet_portal is offline Offline
Newbie Poster

jsp with mysql connection

 
0
  #1
Feb 8th, 2007
in my each jsp page i have to write this code to connect with Mysql database

Class.forName("com.mysql.jdbc.Driver").newInstance();
String url ="jdbc:mysql://35.212.176.25/tri";
Connection con = DriverManager.getConnection(url,"root", "");

now i want to make this code in a separate jsp page and then only include this page in my current jsp page where ever necessary to connect with my Database like in PHP. Is it possible in Jsp . If yes pls tell me
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: jsp with mysql connection

 
0
  #2
Feb 8th, 2007
You should move it out to a Servlet, bean, custom JSTL tag, or other application context item. This type of code should never be found in a JSP.

Other than that, yes it is possible.

Try going through the following:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
(although it is one version outdated now)
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: jsp with mysql connection

 
0
  #3
Feb 8th, 2007
yes it's possible and no we're not going to tell you how to do it as it is (as you've already been told) extremely bad to do so.

It is in fact one of the reasons PHP is frowned upon by people who are serious about writing software rather than quickly hacking something together in the hope noone will ever have to change it.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC