• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Can't connect to MySQL database with Hibernate

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm trying to get my program to connect to my database, I've got the connection details here:

MySQL database name: a1847282_animals
MySQL user name: a1847282_adam
Password for MySQL user: passw0rd

Table name: Animals
Field 1: animalID - int size 3
Field 2: animalName - text size 20
Field 3: animalType - text size 20

My Hibernate Config File:


My Hibernate Mapping file


My Mapping Class


Here's my code to save data to the database from a List<Animal>


Now when I try and connect I get these errors:
 
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Welcome to the Ranch!

Adam Compton wrote:



That doesn't look like a Hibernate problem to me. Can you reach your database by other means?
 
Adam Compton
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure how else to do it, the only way I can check to see if it worked is to use PHPMyAdmin on the web host site.

I have these namespaces on the class file that handles the saving and loading but I can't get the getSession() method to create queries:




 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PHPMyAdmin runs on the server, so it is not helpful in this case.

You could try to connect with the MySql Query Browser from your local machine. Or setup the database connection in your IDE (which is handy anyways, especially when you use the JBoss Hibernate tools later). All IDEs have some means of database browser.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Compton wrote:



Hm.... and you have to be sure your web host allows connections from outside (i.e. applications not running on the same server) to the database. For security reasons this typically will not be the case. Then you have to setup a local database for development.
 
Adam Compton
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm quite new to using MySQL in Java and Hibernate, can you tell me how to do it in Netbeans 7?
 
Adam Compton
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay if I can't link to it from the outside is there a way I can upload the .jar file of the program to the web host and run it from there? It's a console based program.

Also can you tell me what namespace I need to implement to get getSession() to work as well for my loadDatabase method?
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find a tutorial at the Netbeans site.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Okay if I can't link to it from the outside is there a way I can upload the .jar file of the program to the web host and run it from there?



I doubt it. You need a shell access and Java installed. Then it is just as any other system, if you want to use it as console tool and not as a web app.

Do you have a dedicated or virtual server? Then yes, you can do whatever you want. Within the typical (cheap) web package? Next to no chance. Most probably you can run PHP there...
 
Adam Compton
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've changed to using a local database within NetBeans and I've almost got it to work but I'm having some issues either regarding the mapping or the way I'm using the sessionfactory.

Configuration file, I think it's working 100% now.


The database is called AnimalsDatabase:
Table: Animals
PK: id - integer
name - varchar
type - varchar

Now the thing I'm confused about is when I created the table the names were all lowercase but on the Services database explorer they come up as full CAPS.

The Mapping File:


The save method in my program:



Here are the errors:

 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic