tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Teh Noranis Mohd Aris <teh_nora...@yahoo.com>
Subject Re: Using servlet and mysql
Date Tue, 29 May 2007 06:59:08 GMT
Dear All,
   
  I already put mysql database driver (jar file) in directory catalina_home\common\lib and
changed 8080 to 3306 but I got the error "java.sql.SQLException: Unable to connect to any
hosts due to exception: java.net.ConnectException: Connection refused: connect". What should
be the matter? I put the database name, teh in directory catalina_home\webapps\ROOT\. Is this
correct? In which directory should I actually put the database name? Please help. I'm running
out of time! Thank you so much.
   
  Yours Sincerely,
  TEH

Foo Shyn <fooshyn@optegra.com.my> wrote:
  Hi,

You'll need to get the MySQL database driver and put them in the 
{catalina_home}\common\lib folder. The driver can be easily obtained 
through MySQL site.
BTW, as far as i know, the default port for MySQL database is 3306, so 
you might wanna change that. 8080 is for Tomcat, not the database.

Seems like not many new users of connection pooling went through 
Apache's documents. Please don't waste their effort, take a look at it 
before you start to attempt anything.

HTH,
FooShyn

Teh Noranis Mohd Aris wrote:
> Thank you so much for the reply. I've put "jdbc:mysql://localhost:8080/teh but I got
the error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. I'm very new to using mysql
database and servlet. Can you please explain to me how to create the database name and its
fields? Should I install any driver? How can it be done? Please help. Thank you.
> 
> Yours Sincerely,
> TEH 
>
> Foo Shyn wrote:
> Hi,
>
> yyyy would be ur database port, xxx will be ur database name
>
> HTH
> FooShyn
>
> Teh Noranis Mohd Aris wrote:
> 
>> Hi,
>>
>> I would like to access mysql database from a servlet but I'm not sure what to initialize
for the String connectionURL marked as "jdbc:mysql://localhost:yyyy/xxx" in the program below.
I got this program from the internet which I would like to run in my computer. Can anyone
please explain to me what the parameters "yyyy" and "xxx" should be?
>>
>> Yours Sincerely,
>> TEH
>>
>> Following is part of the program:
>> .......
>> public void doPost(HttpServletRequest request, HttpServletResponse 
>> response) throws ServletException, IOException{
>> response.setContentType("text/html");
>> PrintWriter pw = response.getWriter();
>> String connectionURL = "jdbc:mysql://localhost:yyyy/xxx";
>> Connection connection=null;
>> try{
>> String username = request.getParameter("username");
>> String password = request.getParameter("password");
>> pw.println(username);
>> pw.println(password);
>> Class.forName("com.mysql.jdbc.Driver").newInstance();
>> connection = DriverManager.getConnection(connectionURL, "root", "root");
>> PreparedStatement pst = connection.prepareStatement
>> ("insert into login_table values(?,?)");
>> .......
>>
>>
>> ---------------------------------
>> Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on, when.

>>
>> ------------------------------------------------------------------------
>>
>> No virus found in this incoming message.
>> Checked by AVG Free Edition. 
>> Version: 7.5.472 / Virus Database: 269.8.0/821 - Release Date: 5/27/2007 3:05 PM
>>
>> 
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> 
> ---------------------------------
> Shape Yahoo! in your own image. Join our Network Research Panel today!
> 
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.472 / Virus Database: 269.8.0/821 - Release Date: 5/27/2007 3:05 PM
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



       
---------------------------------
Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos &
more. 
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message