Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Databases > Re: trouble con...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 11 Topic 3700 of 3800
Post > Topic >>

Re: trouble connecting to mysql

by Lew <lew@[EMAIL PROTECTED] > Apr 6, 2008 at 03:54 PM

Arne Vajhøj wrote:
> naveen wrote:
>> hello friends
>> i have just touched jsp programming and i m having trouble connecting
>> to mysql database.
>> I m using tomcat 6
>>
>> the connection part of the code of my jsp (HelloMySql.jsp) is-->
> 
>> String dbURL="jdbc:mysql:localhost\\neo";
>> String username="root";
>> String passwd="abc";
>> try{
>>     Class.forName("com.mysql.jdbc.Driver");
>>     Connection conn=DriverManager.getConnection(dbURL,username,passwd);
> 
>> i m using this driver -->
>> mysql-connector-java-5.1.6-bin.jar
>> and have put it in this location
>> C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib
>>
>> further i have appended this to the Classpath environment variable -->
>> C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\mysql-
>> connector-java-5.1.6-bin.jar
>>
>> but the sever returns error that
>> No suitable driver found
> 
> Unless you want to use container managed connection pool you
> should put the jar file in your web apps WEB-INF/lib.
> 
> The connection URL looks wrong as well. It should be
> something like:
> 
> "jdbc:mysql://localhost/neo"

Also, it's pretty pointless to keep calling
  Class.forName("com.mysql.jdbc.Driver");
after the first time in a program run.  Once the driver is loaded, it's 
loaded, and loading it again is redundant.

Also, move your Java source code ("scriptlet") out of the JSP and into a
Java 
servlet source file.  Research the "Model-View-Controller" (MVC) pattern
and 
what Sun calls the "Model 2" web-app architecture.  Among other things, it

will refactor your database connection code back two layers where it
belongs.

-- 
Lew
 




 11 Posts in Topic:
trouble connecting to mysql
naveen <naveen.cse217@  2008-04-06 10:03:41 
Re: trouble connecting to mysql
=?ISO-8859-1?Q?Arne_Vajh=  2008-04-06 15:07:58 
Re: trouble connecting to mysql
Lew <lew@[EMAIL PROTEC  2008-04-06 15:54:55 
Re: trouble connecting to mysql
naveen <naveen.cse217@  2008-04-07 02:28:27 
Re: trouble connecting to mysql
=?ISO-8859-1?Q?Arne_Vajh=  2008-04-07 21:40:57 
Re: trouble connecting to mysql
"joeNOSPAM@[EMAIL PR  2008-04-07 09:23:31 
Re: trouble connecting to mysql
naveen <naveen.cse217@  2008-04-08 19:05:48 
Re: trouble connecting to mysql
=?ISO-8859-1?Q?Arne_Vajh=  2008-04-08 22:24:21 
Re: trouble connecting to mysql
naveen <naveen.cse217@  2008-04-09 06:02:49 
Re: trouble connecting to mysql
Lew <lew@[EMAIL PROTEC  2008-04-09 19:52:50 
Re: trouble connecting to mysql
naveen <naveen.cse217@  2008-04-10 11:56:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 17:23:51 CDT 2008.