Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package mysql_oop;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.Statement;
  11.  
  12. /**
  13. *
  14. * @author ACER
  15. */
  16. public class Mysql_oop {
  17. static final String jdbc_drivernya = "com.mysql.jdbc.Driver";
  18. static final String db_url = "jdbc:mysql://mysql.idhostinger.com:3306/u375462326_aplab";
  19.  
  20. static final String USER = "u375462326_rts";
  21. static final String PASS = "123456";
  22. /**
  23. * @param args the command line arguments
  24. */
  25. public static void main(String[] args){
  26. // TODO code application logic here
  27. Connection conn = null;
  28. Statement stmt = null;
  29. try{
  30. Class.forName(jdbc_drivernya);
  31. conn = DriverManager.getConnection(db_url, USER, PASS);
  32. System.out.println("Deleting database...");
  33. stmt = conn.createStatement();
  34.  
  35. conn = DriverManager.getConnection(db_url, USER, PASS);
  36.  
  37. stmt = conn.createStatement();
  38.  
  39. String sql = "CREATE TABLE Person"
  40. + "(id INTEGER not NULL, "
  41. + " firstName VARCHAR(50), "
  42. + " lastName VARCHAR(50), "
  43. + " age INTEGER, "
  44. + " PRIMARY KEY ( id ))";
  45.  
  46. stmt.executeUpdate(sql);
  47. System.out.println("Created table in given database...");
  48. stmt.close();
  49. conn.close();
  50. }catch(Exception e){
  51. System.out.println(e.getMessage());
  52. }
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement