Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package domyslny;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- public class Main {
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- createTable();
- }
- public static void createTable() throws Exception{
- try {
- Connection con = getConnection();
- PreparedStatement create = con.prepareStatement("CREATE TABLE IF NOT EXIST aaaa(id int NO NULL AUTO_INCREMENT, first varchar(255), last varchar(255), PRIMARY KEY (id))");
- create.executeUpdate();
- }catch(Exception e) {System.out.println(e);}
- finally {System.out.println("Function complete.");}
- }
- public static Connection getConnection() throws Exception{
- try {
- String driver = "com.mysql.jdbc.wypozyczalnia";
- String url = "jdbc:mysql://localhost:1521/wypozyczalnia";
- String username="LUKASBURZA";
- String password = "abcd";
- Class.forName(driver);
- Connection conn = DriverManager.getConnection(url, username, password);
- System.out.println("Connected");
- return conn;
- }catch(Exception e) {System.out.println(e);}
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement