Guest User

Untitled

a guest
May 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.SQLException;
  5.  
  6. public class DbTest {
  7. private Connection connection;
  8. public void createDb(String name) throws SQLException {
  9. connection = DriverManager.getConnection
  10. ("jdbc:mysql://localhost/?user=root&password=root");
  11.  
  12. String createDbSql = "CREATE DATABASE IF NOT EXISTS ?";
  13. PreparedStatement createDbStat = connection.prepareStatement(createDbSql);
  14. createDbStat.setString(1,name);
  15. createDbStat.executeUpdate();
  16. }
  17.  
  18. DbTest() {
  19. try {
  20. createDb("Algebra");
  21. } catch (SQLException e) {
  22. e.printStackTrace();
  23. }
  24. }
  25.  
  26. public static void main(String[] args) {
  27. new DbTest();
  28. }
  29. }
Add Comment
Please, Sign In to add comment