import java.sql.*;

public class Main{
  //  public class GetAllRows{
public static void main(String[] args) {
System.out.println("Getting All Rows from a table!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "csc314";
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM  employee");
System.out.println("EmployeeNumber: " + "\t" + "FirstName: ");
while (res.next()) {
int i = res.getInt("EmployeeNumber");
String s = res.getString("FirstName");
System.out.println(i + "\t\t" + s);
}
con.close();
}
catch (SQLException s){
System.out.println("SQL code does not execute.");

}
catch (Exception e){
e.printStackTrace();
}
}
}

Last modified: Wednesday, April 29, 2015, 11:31 AM