Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- public class DbTest {
- private Connection connection;
- public void createDb(String name) throws SQLException {
- connection = DriverManager.getConnection
- ("jdbc:mysql://localhost/?user=root&password=root");
- String createDbSql = "CREATE DATABASE IF NOT EXISTS ?";
- PreparedStatement createDbStat = connection.prepareStatement(createDbSql);
- createDbStat.setString(1,name);
- createDbStat.executeUpdate();
- }
- DbTest() {
- try {
- createDb("Algebra");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- new DbTest();
- }
- }
Add Comment
Please, Sign In to add comment