|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.upc.dama.dex.io.JDBCReader
public class JDBCReader
A very simple JDBC reader.
This reader allows for getting rows from a relational database
using the JDBC interface.
To use it you must get the JDBC driver of your database.
After this, you can execute a query over the database and get the result row
by row.
Basic example using a MySQL database:
RowReader rl = new JDBCReader("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/example", "SELECT * FROM `test` "); String[] r; while ((r = rl.readNext()) != null) { for (int i = 0; i < r.length; i++) { System.out.println(r[i]); } }
| Constructor Summary | |
|---|---|
JDBCReader(java.lang.String driverUrl,
java.lang.String url,
java.lang.String query)
Creates a new instance of JDBCReader. |
|
JDBCReader(java.lang.String driverUrl,
java.lang.String protocol,
java.lang.String database,
java.lang.String query)
Creates a new instance of JDBCReader. |
|
JDBCReader(java.lang.String driverUrl,
java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String query)
Creates a new instance of JDBCReader. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the underlying reader. |
int |
getRow()
The row number for the current row. |
java.lang.String[] |
readNext()
Reads the next row as a string array. |
boolean |
reset()
Moves the reader to the first row of the result of the query. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JDBCReader(java.lang.String driverUrl,
java.lang.String protocol,
java.lang.String database,
java.lang.String query)
throws java.io.IOException
JDBCReader.
driverUrl - JDBC driver url .protocol - Protocol to be used for the JDBC connection.database - Name of the database.query - Query to be executed on the database.
java.io.IOException
public JDBCReader(java.lang.String driverUrl,
java.lang.String url,
java.lang.String query)
throws java.io.IOException
JDBCReader.
driverUrl - JDBC driver urlurl - JDBC url connection to the database.query - Query to be executed on the database.
java.io.IOException
public JDBCReader(java.lang.String driverUrl,
java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String query)
throws java.io.IOException
JDBCReader.
driverUrl - JDBC driver urlurl - JDBC url connection to the database.user - Username of the database.password - Password of to the database.query - Query to be executed on the database.
java.io.IOException| Method Detail |
|---|
public boolean reset()
throws java.io.IOException
Restarts the reader.
reset in interface RowReadertrue.
java.io.IOException - If bad things happen.
public java.lang.String[] readNext()
throws java.io.IOException
readNext in interface RowReaderjava.io.IOException - If bad things happen during the read.
public void close()
throws java.io.IOException
close in interface RowReaderjava.io.IOException - If the close fails.
public int getRow()
throws java.io.IOException
getRow in interface RowReaderjava.io.IOException - If it fails.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||