File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes creating table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "creating table" Watch "creating table" New topic

creating table

Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
I'm just learning Java, through a college course. I have been given an assignment to create two tables and populate them with information. I have spent a litte time searching the API hoping for some help but I didn't really know where to start looking. What I need to know first is how to create the table. I know to use ("CREATE TABLE <table name> ()"); Do I put the name of each column in the ()? Are they separated by commas? Along with the name do I put the type and the size?
I have more questions if you don't mind helping, but this could get me started.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
I'd recommend taking a look at The Creating Tables section at
And perhaps a simple example will help. The following SQL statement would work to create a new table named student with three columns - idNo, fName, and lName - in a MySQL database.
create table student (
  idNo varchar(11) not null,
  fName varchar(32),
  lName varchar(32)
This statement specifies that idNo is a char field up to 11 characters big that is not allowed to be empty (not null). fName and lName are fields up to 32 characters each.
Available column types do differ between different database vendors. For example, Oracle has a column type called varchar2, while MySQL does not. So, a table creation statement for one database vendor might not work on another.
When figuring out table creation statements, it can be nice to have the documentation at hand. The documentation for the MySQL Column Types can be found at
Figuring it out?
[ April 26, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: creating table
It's not a secret anymore!