471,108 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

NumberFormatException: For string 'localhost'

Joe
Hi,

I am trying to connect to a MySQL database through a Java Servlet. I
think I have correctly installed Tomcat 4.1.30 and the MySQL Database
along with ConnectorJ. I am getting a NumberFormatException at the
following piece of code:

Connection connection = null;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/mydatabase";
String username = "user";
String password = "password";

//exception gets thrown here
connection = DriverManager.getConnection(url, username,
password);

Here is the Exception thrown:
java.lang.NumberFormatException: For input string "localhost"

If I understand why a NumberFormatException is thrown, it is because
it is having trouble turning localhost into some sort of number. I've
tried various things like using my IP instead of localhost, getting
rid of the port and combinations of the like. I can successfully
connect to a MySQL database at my work using its web location. If
anyone could help shed some light on this problem, it would be greatly
appreciated.

thanks,
Joe
Jul 20 '05 #1
0 1497

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by YinTat | last post: by
3 posts views Thread by Justnew | last post: by
8 posts views Thread by John Salerno | last post: by
13 posts views Thread by Andrew | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.