Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tool to generate a Class from MySQL table (Model Class for MVC Pattern)

 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I'm looking for a tool to generate a Class with all the variables, getters and setters from a MySQL table.
I'm using Netbeans and Eclipse IDE to develop Webapplications.
Suggestions?

kind regards,
Mark
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out our own Jenny code generator.
 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've download the jr.jar and put it in the "C:\Program Files (x86)\Java\jdk1.6.0\bin" map.
This map is in the Classpath but I receive NoClassDefFoundError.

command-line: java com.javaranch.db.Jenny tennis.properties (from the c:\temp map)

What goes wrong?


 
Paul Clapham
Sheriff
Posts: 21297
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't specified the class path. And don't put jar files in your JDK folders. Put them somewhere else (I have a folder called C:\Javastuff for example) and point there when you specify the class path.
 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand :-(
I put C:\javastuff in the CLASSPATH (windows systemvariables). The jr.jar is also in the c:\javastuff map.
Then I do cd c:\javastuff and then "java com.javaranch.db.Jenny tennis.properties"
Result is a java.lang.ClassNotFoundException, can't find the main class com.javaranch.db.Jenny
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAR files need to be part of the CLASSPATH variable themselves, not just the folder they are on.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse: If it is a JPA project (or has the JPA facet): Project's context menu, JPA tools, Generate Entities from tables. If it is not a JPA project per se, make it so temporarily.

Netbeans: IIRC in the "New" menu, Entity from Tables.

Or do I miss something fundamentally?
 
mark reusen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank's, Eclipse works fine! Now I have a Class for every Table (with all the attributes and getters and setters).
Is it also possible to generate an IO Class (with the SQL query inside) for the Table, which uses the Class mentioned above?
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you wouldn't write SQL code yourself with JPA the tools I mentioned don't have support for this.

If you were using Spring then you could look into the JdbcDaoSupport. If you really need to write the SQL yourself a framework like iBatis could help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic