package com;
import java.sql.*;
public class Main {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://10.64.6.9/university";
static final String USER = "st_fcit";
static final String PASS = "111111";
public static void main(String s[]){
Connection conn = null;
Statement stmtInsert = null;
Statement stmtCreate = null;
Statement stmtDrop = null;
Statement stmtRead = null;
PreparedStatement parametersInsert;
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
stmtDrop.executeUpdate("DROP TABLE user;");
System.out.println("Creating statement...");
stmtCreate = conn.createStatement();
String commandCreate = "CREATE TABLE user " +
"(id int not NULL, " +
" name VARCHAR(50), " +
" telephone VARCHAR(50), " +
" PRIMARY KEY ( id ))";
stmtCreate.executeUpdate(commandCreate);
String commandDrop = "DROP TABLE user;";
stmtDrop.executeUpdate(commandDrop);
/*
String name = "Andriy";
String phone = "1234567890";
parametersInsert =conn.prepareStatement("INSERT INTO user(name,telephone) VALUES (?, ?)");
parametersInsert.setString(1, name);
parametersInsert.setString(2, phone);
parametersInsert.executeUpdate();
String sql;
sql = "SELECT * FROM user";
ResultSet rs = stmtRead.executeQuery(sql);
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
String name1 = rs.getString("name");
String telephone = rs.getString("telephone");
//Display values
System.out.println(" name: " + name1);
System.out.println(" telephone: " + telephone);
}
String commandDrop = "DROP TABLE user;";
stmtDrop.executeUpdate(commandDrop);
/*
String sql;
sql = "SELECT * FROM curator";
ResultSet rs = stmt.executeQuery(sql);
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
String personID = rs.getString("personID");
String curatorID = rs.getString("curatorID");
//Display values
System.out.println(" personID: " + personID);
System.out.println(" curatorID: " +curatorID);
}
*/
} catch (Exception ex) {
// handle the error
System.out.print("Exception : " + ex.getMessage());
}
System.out.println("^_^");
}
}