Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.ayumi.dbt;
- import java.sql.*;
- public class Main {
- public static Connection connection;
- public static Statement s;
- public static void main(String[] args) throws SQLException {
- connection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/user?user=root&password=Nikodem");
- DatabaseMetaData dbm = connection.getMetaData();
- // check if "employee" table is there
- ResultSet tables = dbm.getTables(null, null, "REGISTRATION", null);
- if (tables.next()) {
- String upd = "INSERT INTO REGISTRATION(ID, FIRST, LAST, AGE) " +
- "VALUES (3, 'test', 'tes', 25)";
- s.executeUpdate(upd);
- }
- else {
- // Table does not exist
- String sql = "CREATE TABLE REGISTRATION " +
- "(id INTEGER not NULL, " +
- " first VARCHAR(255), " +
- " last VARCHAR(255), " +
- " age INTEGER, " +
- " PRIMARY KEY ( id ))";
- s = connection.createStatement();
- s.execute(sql);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement