Google

Thursday, August 16, 2007

Creating Tables in Java using JDBC

import java.sql.*;
import java.io.IOException;
import java.io.PrintStream;
import java.sql.*;
import java.io.*;
import java.net.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;

class CreateTableEx{
public static void main(String args[])
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection"jdbc:mysql://localhost:3306/test/user=yes&password=null");
Statement stmt=con.createStatement();
stmt.executeUpdate("create table tablename(eno integer,ename varchar(20),esal float,eaddr varchar(30))");
stmt.executeUpdate("insert into table values(01,'ramesh',100,'banjarahills')");
stmt.executeUpdate("insert into table values(02,'ram',5000,'ameerpet')");
stmt.close();
stmt.close();
}
catch(SQLException e)
{
System.out.println(e);
}
catch(ClassNotFoundException e){
System.out.println(e);
}

}
}

No comments: