diff --git a/.idea/copyright/dw_jdbc.xml b/.idea/copyright/dw_jdbc.xml deleted file mode 100644 index 3f321e9..0000000 --- a/.idea/copyright/dw_jdbc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/README.md b/README.md index 5abee59..e4346f2 100644 --- a/README.md +++ b/README.md @@ -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, "", ""); + 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`. \ No newline at end of file diff --git a/src/test/java/world/data/jdbc/SparqlTest.java b/src/test/java/world/data/jdbc/SparqlTest.java index 5de082e..3cb960c 100644 --- a/src/test/java/world/data/jdbc/SparqlTest.java +++ b/src/test/java/world/data/jdbc/SparqlTest.java @@ -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";