Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- //import java.util.Scanner;
- public class EventCreation
- {
- public static void main(String[] args ) throws SQLException
- {
- /* Scanner sc = new Scanner(System.in);
- System.out.println("Enter The Table Name : ");
- String table_name = reader.nextLine(); */
- String Driver ="com.mysql.java.Driver";
- String url="jdbc:mysql://localhost:3306/dbForJava";
- String uName="student";
- String pwd="student";
- Connection conn=null;
- try
- {
- conn=DriverManager.getConnection(url,uName,pwd);
- String sql="create table Event(Event_ID int primary key,Event_Name varchar(30), Event_Host varchar(30))";
- PreparedStatement stmt=conn.prepareStatement(sql);
- int rs= stmt.executeUpdate();
- if(rs==1)
- {
- System.out.println("Table created");
- }
- else
- {
- System.out.println("Table not created");
- }
- conn.close();
- }
- catch(Exception e)
- {
- {
- System.out.println("Got an Exception");
- System.out.println(e.getMessage());
- System.out.println(e);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment