Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package performance;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Scanner;
- public class firstques {
- public static void main(String[] args) throws SQLException {
- // TODO Auto-generated method stub
- try
- {
- Connection con;
- Statement stmt;
- Scanner sc;
- sc=new Scanner(System.in);
- final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
- Class.forName("com.mysql.jdbc.Driver");
- con=DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","");
- stmt=con.createStatement();
- System.out.println("Creating Table Please Wait...\n\n");
- Thread.sleep(1000);
- String sql="CREATE or replace TABLE `employee_data` (`name` text NOT NULL,`salary` int(255) NOT NULL,`id` int(125) NOT NULL,`dept` varchar(255) NOT NULL)";
- stmt.execute(sql);
- System.out.println("Employee Table Created Sucessfully.");
- System.out.println("\n\n Alter Table : ");
- System.out.println("\nEnter a new column name which you want to add into the employee table :\n(Don't add the space between column name)");
- String col=sc.next();
- sql="alter TABLE `employee_data` add "+col+" varchar(255)";
- stmt.execute(sql);
- System.out.println(col+ " Column is added in Employee Table");
- System.out.println("\n\n If you want to drop database then type Y : \n\n");
- String y=sc.next();
- if(y.equals("y")|| y.equals("Y"))
- {
- sql="drop TABLE `employee_data`";
- stmt.execute(sql);
- System.out.println("Employee table is deleted");
- }
- sc.close();
- con.close();
- stmt.close();
- }
- catch(Exception e)
- {
- System.out.println("Exception Occured : "+e);
- }
- }
- }
Add Comment
Please, Sign In to add comment