Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Griffith committed Nov 14, 2016
1 parent ae7ff19 commit a5d5be2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
7 changes: 0 additions & 7 deletions .idea/copyright/dw_jdbc.xml

This file was deleted.

54 changes: 53 additions & 1 deletion README.md
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`.
2 changes: 1 addition & 1 deletion src/test/java/world/data/jdbc/SparqlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void testConstruct() throws Exception {
}
assertThat(lastUri).isEqualTo("http://localhost:3333/sparql/dave/lahman-sabremetrics-dataset?query=CONSTRUCT+%0A++%7B+%0A++++%3Fo+%3Fp+%3Fs+.%0A++%7D%0AWHERE%0A++%7B+%3Fs++%3Fp++%3Fo+%7D%0ALIMIT+++10%0A");
}

@org.junit.Test
public void testConstructTurtle() throws Exception {
resultResourceName = "construct.ttl";
Expand Down

0 comments on commit a5d5be2

Please sign in to comment.