Home Jdbc Jdbc-mysql Creating a MySQL Database Table to store Java Types



Creating a MySQL Database Table to store Java Types
Posted on: April 13, 2007 at 12:00 AM
Dear user, consider a case where we need to store a java types in our database table. Now one question may arise in your mind that whether the MySQL supports java types or not.

Creating a MySQL Database Table to store Java Types

     

Dear user, consider a case where we need to store a java types in our database table. Now one question may arise in your mind that whether the MySQL supports java types or not. This section describes how to create a table in MySQL database that stores all java types. Here we are providing you an example with code for creating a table to store java types. Brief description is given below:

Description of program:

In this program we are going to establish the connection between MySQL database table and java file. After the connection has been established creates a database table for storing all java types. We have used most of the java types provided to us by the jdbc. 

Here is the code of program:

import java.sql.*;

public class CreateMySqlTable{
  
  public static void main(String[] args) {
  System.out.println("Creating a Mysql Table to Store Java Types!");
  Connection con = null;
  String url = "jdbc:mysql://localhost:3306/";
  String db = "jdbctutorial";
  String driver = "com.mysql.jdbc.Driver";
  String user = "root";
  String pass = "root";
  try{
  Class.forName(driver).newInstance();
  con = DriverManager.getConnection(url+db, user, pass);
  try{
  Statement st = con.createStatement();
<<<<<<< CreateMySqlTable.shtml    String table = 
"CREATE TABLE java_DataTypes2

("
"typ_boolean BOOL, "  
=======   String table 
"CREATE TABLE java_DataTypes2(""typ_boolean BOOL, "  
>>>>>>> 1.7   "typ_byte  TINYINT, "  
  "typ_short SMALLINT, "  
  "typ_int INTEGER, " 
  "typ_long  BIGINT, "  
  "typ_float FLOAT, " 
  "typ_double  DOUBLE PRECISION, "  
  "typ_bigdecimal  DECIMAL(13,0), "  
  "typ_string  VARCHAR(254), "  
  "typ_date  DATE, "  
  "typ_time  TIME, "  
  "typ_timestamp TIMESTAMP, " 
  "typ_asciistream TEXT, "  
  "typ_binarystream  LONGBLOB, "  
  "typ_blob  BLOB)"
 

 st.executeUpdate(table);
  System.out.println(table);
 
con.close
();
 }
  catch (SQLException s){
  System.out.println
(
"Table is all ready exists!");
 }
  }
  catch (Exception e){
  e.printStackTrace();
  }
  }
}

Download this example.

Related Tags for Creating a MySQL Database Table to store Java Types:
javasqlmysqlcdatabasetabledataiotypestypevithisidcreatetabforexamplewithtobaseexamstoreeitdessectionpeinasmjesaseallhowprocreatingdescribetorxaxampsatmyishallmpleaarcodcodevascrssrithavbesstabablatihatpleplprodeono


More Tutorials from this section

Ask Questions?    Discuss: Creating a MySQL Database Table to store Java Types   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.