Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class CreateTableJdbc {
- static final String DATABASE_URL = "jdbc:mysql://localhost/PROSELYTE_JDBC_DB";
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String USER = "ВАШЕ_ИМЯ_ПОЛЬЗОВАТЕЛЯ";
- static final String PASSWORD = "ВАШ_ПАРОЛЬ";
- public static void main(String[] args) throws ClassNotFoundException, SQLException {
- Connection connection = null;
- Statement statement = null;
- try {
- System.out.println("Registering JDBC driver...");
- Class.forName(JDBC_DRIVER);
- System.out.println("Creating connection to database...");
- connection = DriverManager.getConnection(DATABASE_URL, USER, PASSWORD);
- System.out.println("Creating table in selected database...");
- statement = connection.createStatement();
- String SQL = "CREATE TABLE developers " +
- "(id INTEGER not NULL, " +
- " name VARCHAR(50), " +
- " specialty VARCHAR (50), " +
- " salary INTEGER not NULL, " +
- " PRIMARY KEY (id))";
- statement.executeUpdate(SQL);
- System.out.println("Table successfully created...");
- }finally {
- if(statement!=null){
- statement.close();
- }
- if(connection!=null){
- connection.close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement