Create Table

Leave a reply                     

Create Table in Java

MySql Create Table

Java Create Table

How to Create Table In MySql in Java?

Following program creates table tablename in MySql database databasename.
columnname1 and columnname2 are name of columns in table.
auto_increment is used to make column auto increment.
primary key makes columnname1 primary key.


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class CreateTable {

	 * @param args
	public static void main(String[] args) {
		try {
			Connection connection = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/databasename", "root", "");
			Statement statement = connection.createStatement();
					.executeUpdate("CREATE TABLE tablename(columnname1 int(5) auto_increment primary key, columnname2 varchar(128))");
		} catch (SQLException e) {
		} catch (ClassNotFoundException e) {

Leave a Reply

Your email address will not be published. Required fields are marked *

two + 3 =