Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package pl.ayumi.dbt;
  2.  
  3. import java.sql.*;
  4.  
  5. public class Main {
  6. public static Connection connection;
  7. public static Statement s;
  8.  
  9. public static void main(String[] args) throws SQLException {
  10. connection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/user?user=root&password=Nikodem");
  11. DatabaseMetaData dbm = connection.getMetaData();
  12. // check if "employee" table is there
  13. ResultSet tables = dbm.getTables(null, null, "REGISTRATION", null);
  14. if (tables.next()) {
  15. String upd = "INSERT INTO REGISTRATION(ID, FIRST, LAST, AGE) " +
  16. "VALUES (3, 'test', 'tes', 25)";
  17. s.executeUpdate(upd);
  18. }
  19. else {
  20. // Table does not exist
  21.  
  22. String sql = "CREATE TABLE REGISTRATION " +
  23. "(id INTEGER not NULL, " +
  24. " first VARCHAR(255), " +
  25. " last VARCHAR(255), " +
  26. " age INTEGER, " +
  27. " PRIMARY KEY ( id ))";
  28.  
  29. s = connection.createStatement();
  30. s.execute(sql);
  31. }
  32.  
  33.  
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement