package com.dev;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
try {
System.out.println("Hellow World");
String url = "jdbc:mysql://localhost/test";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection (url, "root", "password");
System.out.println("Connection established...");
Statement st = conn.createStatement();
st.execute("CREATE TABLE EXAMPLETABLE (FIRSTNAME VARCHAR(20), LASTNAME VARCHAR(20), GENDER CHAR(1), DATEOFBIRTH DATE)");
System.out.println("Table created...");
Statement st1 = conn.createStatement();
st1.execute("INSERT INTO EXAMPLETABLE(FIRSTNAME, LASTNAME, GENDER, DATEOFBIRTH) VALUES('RAMA','DASHARATHA','M','1907-05-06')");
System.out.println("ROW INSERTED...");
Statement st2 = conn.createStatement();
ResultSet rs = st2.executeQuery("SELECT * FROM EXAMPLETABLE");
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getDate(4));
}
System.out.println("VALUES RETRIVED FROM TABLE...");
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
try {
System.out.println("Hellow World");
String url = "jdbc:mysql://localhost/test";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection (url, "root", "password");
System.out.println("Connection established...");
Statement st = conn.createStatement();
st.execute("CREATE TABLE EXAMPLETABLE (FIRSTNAME VARCHAR(20), LASTNAME VARCHAR(20), GENDER CHAR(1), DATEOFBIRTH DATE)");
System.out.println("Table created...");
Statement st1 = conn.createStatement();
st1.execute("INSERT INTO EXAMPLETABLE(FIRSTNAME, LASTNAME, GENDER, DATEOFBIRTH) VALUES('RAMA','DASHARATHA','M','1907-05-06')");
System.out.println("ROW INSERTED...");
Statement st2 = conn.createStatement();
ResultSet rs = st2.executeQuery("SELECT * FROM EXAMPLETABLE");
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getDate(4));
}
System.out.println("VALUES RETRIVED FROM TABLE...");
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
default user: root
default password: password as given while installation
default schema name: mysql /test
command to switch database from command prompt: use mysql or use test