Win a copy of Learning Java by Building Android Games this week in the Android 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Help getting MYSQL JDBC to work  RSS feed

 
Ranch Hand
Posts: 135
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all. I could really use some help. I am trying to connect to a MySql database on goDaddy and I cannot get this to work. I am sure there is something wrong concerning the JDBC driver but I cannot figure out what it is. I have spent hours on Stack Overflow and it seems every thread I read says the same thing, which is "make sure to add the classpath to the driver. I have did this, I think, and it still will not work. I am getting this error:



What I have done so far is downloaded the driver from MySQL Connector/J. I unzipped the directory and put it into my Java folder on the C: drive since that is what I did with the MS SQL driver. I then went into my environment variables, added a new variable called CLASSPATH and gave it the value of C:\Program Files\Java\mysql-connector-java-5.1.29\mysql-connector-java-5.1.29-bin.jar

I also read that I should put that jar file into the Tomcat lib directory so I did that.
I also read that I should do the following:

Right click project
Go to properties
Go to libraries tab
Click Add External JARs
Find the above JAR file and add it

I have done this as well. I have restarted the Tomcat server and as far as I can tell, rebuilt the project.

I must be doing something wrong or missing something but I have no idea what. Below is my code and below that is the error.




 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never seen the @myhostname.com designation of a server, nor the colon before the DB name. A quick googling found http://stackoverflow.com/questions/1457716/what-is-the-mysql-jdbc-driver-connection-string
 
Raymond Gillespie
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:I've never seen the @myhostname.com designation of a server, nor the colon before the DB name. A quick googling found http://stackoverflow.com/questions/1457716/what-is-the-mysql-jdbc-driver-connection-string



I changed it as the link says but I still get the same error. I am sure that I am doing something wrong concerning the driver but I have no idea what. While something may be wrong with the connection string, if that were my first problem, wouldn't I get a connection error rather than what I am getting?

 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the connection URL you're using now?
 
Raymond Gillespie
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:What's the connection URL you're using now?



 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't look like what's mentioned in that article. It has a domain name instead of host name, and it's missing the slashes. Or is the server actually named "myHostName.com"?
 
Raymond Gillespie
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:That doesn't look like what's mentioned in that article. It has a domain name instead of host name, and it's missing the slashes. Or is the server actually named "myHostName.com"?



The server is not named "myHostName.com" I simply replaced my real one so that it is not posted on the forums. What I am using is my goDaddy domain name.

I added the slashes (thanks for pointing that out) and it seems to work now but I am getting access denied so now I must figure that out. I think it is something on the server end.

Thanks for working through this with me. I will post again if I figure out the access issue.
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be amazed if using a domain name works. Usually you'd need an IP address or the physical server name.
 
Raymond Gillespie
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:I'd be amazed if using a domain name works. Usually you'd need an IP address or the physical server name.



It works. I just had to add my IP address to the remote access list inside of Cpanel.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Raymond Gillespie wrote:

Ulf Dittmer wrote:I'd be amazed if using a domain name works. Usually you'd need an IP address or the physical server name.



It works.  I just had to add my IP address to the remote access list inside of Cpanel.



Man you are god,  I cant tell my wishes for you now. Yousolved my problem with this message
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just write

connetion = Driver manager.getConnection("jdbc:mysql:///databasename","username","password");


but dont forget triple forward slash(///)

I think its help you
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!