Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class Connect
- {
- public static void main (String[] args)
- {
- Connection conn = null;
- try
- {
- String userName = "root";
- String password = "aaaaaaa";
- String url = "jdbc:mysql://localhost:3306/user_geometry";
- System.out.println("wat");
- try{
- Class.forName ("com.mysql.jdbc.Driver").newInstance ();
- }
- catch(Exception e)
- {
- System.out.println("Driver not found");
- }
- System.out.println("wat2");
- conn = DriverManager.getConnection (url, userName, password);
- System.out.println ("Database connection established");
- Statement s = conn.createStatement ();
- //-------------------------------
- // int count;
- //
- // System.out.println("Adding rows of animals");
- // Statement s = conn.createStatement ();
- s.executeUpdate ("DROP TABLE IF EXISTS animal");
- // s.executeUpdate (
- // "CREATE TABLE animal ("
- // + "id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
- // + "PRIMARY KEY (id),"
- // + "name CHAR(40), category CHAR(40))");
- // count = s.executeUpdate (
- // "INSERT INTO animal (name, category)"
- // + " VALUES"
- // + "('snake', 'reptile'),"
- // + "('frog', 'amphibian'),"
- // + "('tuna', 'fish'),"
- // + "('racoon', 'mammal')");
- // s.close ();
- //---------------------------------
- System.out.println("Creating table copy");
- // s = conn.createStatement ();
- // s.executeQuery ("SELECT * FROM user_geometry");
- s.executeUpdate("CREATE TABLE bmt LIKE BST");
- // ResultSet rs = s.getResultSet ();
- // count = 0;
- // while (rs.next ())
- // {
- // System.out.println(rs.next());
- // }
- // rs.close ();
- // s.close ();
- // System.out.println (count + " rows were retrieved");
- }
- catch (Exception e)
- {
- System.err.println ("Cannot connect to database server");
- }
- finally
- {
- if (conn != null)
- {
- try
- {
- conn.close ();
- System.out.println ("Database connection terminated");
- }
- catch (Exception e) { /* ignore close errors */ }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement