To connect to a data source, you must know 3 things:
1. make sure you have oracle database or mysql community
server to do this.
2. your should know your username and password
example: username:scott; password:tiger
3. your jdbc driver if your are using oracle, should look like
this: jdbc:oracle:thin:@localhost:1521:xe
Here is the code from Java Tutorial under jdbc section.
I modified some stuff to accommodate to suit my db.
public void connectToAndQueryDatabase(String username, String password) throws SQLException { Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",username,password); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT lname, fname FROM EMPLOYEE"); ArrayList<String> fnameAl = new ArrayList(); while (rs.next()) { String ln = rs.getString("lname"); String fn = rs.getString("fname"); fnameAl.add(fn); } System.out.println(fnameAl); }