Guest User

Untitled

a guest
Jul 31st, 2018
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.sql.*;
  2. //import java.util.Scanner;
  3.  
  4. public class EventCreation
  5. {
  6. public static void main(String[] args ) throws SQLException
  7. {
  8.  
  9. /* Scanner sc = new Scanner(System.in);
  10. System.out.println("Enter The Table Name : ");
  11. String table_name = reader.nextLine(); */
  12.  
  13. String Driver ="com.mysql.java.Driver";
  14. String url="jdbc:mysql://localhost:3306/dbForJava";
  15. String uName="student";
  16. String pwd="student";
  17. Connection conn=null;
  18.  
  19. try
  20. {
  21. conn=DriverManager.getConnection(url,uName,pwd);
  22. String sql="create table Event(Event_ID int primary key,Event_Name varchar(30), Event_Host varchar(30))";
  23. PreparedStatement stmt=conn.prepareStatement(sql);
  24. int rs= stmt.executeUpdate();
  25. if(rs==1)
  26. {
  27. System.out.println("Table created");
  28. }
  29. else
  30. {
  31. System.out.println("Table not created");
  32. }
  33. conn.close();
  34. }
  35. catch(Exception e)
  36. {
  37. {
  38. System.out.println("Got an Exception");
  39. System.out.println(e.getMessage());
  40. System.out.println(e);
  41. }
  42. }
  43.  
  44. }
  45. }
Add Comment
Please, Sign In to add comment