Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.sql.*;
- import java.util.*;
- class Test {
- public static void main(String[] args) {
- try{
- // Class.forName("com.mysql.jdbc.Driver");
- Connection con = connect(); //Connection con = DriverManager.getConnection("jdbc:mysql://localhost/employee:8889", "root", "root");
- Statement stmt = (Statement) con.createStatement();
- int id = 2;
- String name = "mouhamad";
- int salary = 1000;
- //String insert = "INSERT INTO eep VALUES (" + id + ", '" + name + "', " + salary + ")";
- String create = "CREATE TABLE MyGuests (\n" +
- "id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n" +
- "firstname VARCHAR(30) NOT NULL,\n" +
- "lastname VARCHAR(30) NOT NULL,\n" +
- "email VARCHAR(50),\n" +
- "reg_date TIMESTAMP\n" +
- ")";
- //stmt.executeUpdate(insert);
- stmt.execute(create);
- }catch(Exception e) {
- System.err.println("error : "+e);
- }
- }
- public static Connection connect() {
- Connection conn = null;
- try {
- String userName = "root";
- String password = "root";
- String url = "jdbc:mysql://localhost:8889/employee";
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- conn = DriverManager.getConnection(url, userName, password);
- System.out.println("Database connection established");
- } catch (Exception e) {
- System.err.println("Cannot connect to database server");
- e.printStackTrace();
- }
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement