-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dave Griffith
committed
Nov 14, 2016
1 parent
ae7ff19
commit a5d5be2
Showing
3 changed files
with
54 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,54 @@ | ||
# dw-jdbc | ||
JDBC Driver for connecting to data.world | ||
dw-jdbc is a JDBC driver for connecting to datasets hosted on data.world. | ||
It can be used to provide read-only access to any dataset provided by data.world | ||
from any JVM language. dw-jdbc supports query access both in dwSQL | ||
(data.world's SQL dialect) and in SPARQL 1.1, the native query language | ||
for semantic web data sources. | ||
|
||
|
||
##JDBC URLs | ||
|
||
JDBC connects to data source based on a provided JDBC url. data.world | ||
JDBC urls have the form | ||
|
||
jdbc:data:world:[language]:[user id]:[dataset id] | ||
|
||
where [language] is either "sql" or "sparql",[user id] is the data.world | ||
id of the dataset owner, and [dataset id] is the data.world identifier for | ||
the dataset. | ||
|
||
##Sample code (Java 8) | ||
|
||
```java | ||
final String QUERY = "select * from HallOfFame where playerID = ? order by yearid, playerID limit 10" | ||
final String URL = "jdbc:data:world:sql:dave:lahman-sabremetrics-dataset"; | ||
|
||
|
||
try (final Connection connection = // get a connection to the database, which will automatically be closed when done | ||
DriverManager.getConnection(URL, "<your user name>", "<your API token>"); | ||
final PreparedStatement statement = // get a connection to the database, which will automatically be closed when done | ||
connection.prepareStatement(QUERY)) { | ||
statement.setString(1, "alexape01"); //bind a query parameter | ||
try (final ResultSet resultSet = statement.executeQuery()) { //execute the query | ||
ResultSetMetaData rsmd = resultSet.getMetaData(); //print out the column headers | ||
int columnsNumber = rsmd.getColumnCount(); | ||
for (int i = 1; i <= columnsNumber; i++) { | ||
if (i > 1) System.out.print(", "); | ||
System.out.print(rsmd.getColumnName(i)); | ||
} | ||
System.out.println(""); | ||
while (resultSet.next()) { //loop through the query results | ||
for (int i = 1; i <= columnsNumber; i++) { //print out the column headers | ||
if (i > 1) System.out.print(", "); | ||
String columnValue = resultSet.getString(i); | ||
System.out.print(columnValue); | ||
} | ||
System.out.println(""); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
##Building dw-jdbc | ||
|
||
dw-jdbc can be built from the command-line using `mvn clean install`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters