Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. package mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. public class MainApp {
  9.  
  10. private static final String CREATE_TABLE_QUERY=
  11. "CREATE TABLE java_table(id INT AUTO_INCREMENT, java_text VARCHAR(400) UNIQUE," +
  12. " PRIMARY KEY(id))";
  13.  
  14. public static void main(String[] args){
  15. try(Connection connection = getConnection();
  16. Statement statement = connection.createStatement();){
  17. statement.execute(CREATE_TABLE_QUERY);
  18. } catch (SQLException e) {
  19. e.printStackTrace();
  20. }
  21. }
  22.  
  23. private static Connection getConnection() throws SQLException {
  24. return DriverManager.getConnection("jdbc:mysql://localhost:3306/mysqlbase",
  25. "root","root");
  26. }
  27.  
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement