Java Reference
In-Depth Information
This example establishes a connection to our example MySQL database Finances
and provides an access method called getAcctDetails that returns all the data in
the Accounts table, using an ArrayList of Object s to hold the heterogeneous
data set.
package myDAOs;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.*;
public class AccountsDAO implements
private Connection connection;
public AccountsDAO()
throws SQLException, NamingException
Context initialContext = new InitialContext();
Context context =
DataSource dataSource =
connection = dataSource.getConnection();
public ArrayList<Object> getAcctDetails()
throws SQLException
ArrayList<Object> acctDetails = null;
Statement statement = null;
ResultSet results = null;
statement = connection.createStatement();
results = statement.executeQuery(
"SELECT * FROM Accounts");
acctDetails = new ArrayList <Object>();
while (
acctDetails.add(results.getString(3) + " "
+ results.getString(2));
Search WWH ::

Custom Search