Search in sources :

Example 66 with JenaConnection

use of org.apache.jena.jdbc.connections.JenaConnection in project jena by apache.

the class AbstractJenaStatementTests method prepared_statement_setters_17.

/**
     * Tests that the various set methods of {@link JenaPreparedStatement}
     * function correctly
     * 
     * @throws SQLException
     */
@Test
public void prepared_statement_setters_17() throws SQLException {
    JenaConnection conn = this.getConnection();
    JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
    stmt.setObject(1, 12.3f, Types.DOUBLE);
    ParameterizedSparqlString pss = stmt.getParameterizedString();
    Assert.assertTrue(pss.toString().contains("12.3"));
    Assert.assertFalse(pss.toString().contains(XSDDatatype.XSDfloat.getURI()));
    stmt.close();
    conn.close();
}
Also used : ParameterizedSparqlString(org.apache.jena.query.ParameterizedSparqlString) JenaConnection(org.apache.jena.jdbc.connections.JenaConnection) Test(org.junit.Test)

Example 67 with JenaConnection

use of org.apache.jena.jdbc.connections.JenaConnection in project jena by apache.

the class AbstractJenaStatementTests method statement_bad_execute_07.

/**
     * Tests error cases for trying to execute invalid SPARQL
     * 
     * @throws SQLException
     */
@Test(expected = SQLException.class)
public void statement_bad_execute_07() throws SQLException {
    JenaConnection conn = this.getConnection();
    Statement stmt = conn.createStatement();
    try {
        stmt.executeUpdate("SELECT * WHERE {", 0);
    } finally {
        stmt.close();
        conn.close();
    }
}
Also used : JenaConnection(org.apache.jena.jdbc.connections.JenaConnection) Test(org.junit.Test)

Example 68 with JenaConnection

use of org.apache.jena.jdbc.connections.JenaConnection in project jena by apache.

the class AbstractJenaStatementTests method prepared_statement_setters_51.

/**
     * Tests that the various set methods of {@link JenaPreparedStatement}
     * function correctly
     * 
     * @throws SQLException
     */
@Test
public void prepared_statement_setters_51() throws SQLException {
    JenaConnection conn = this.getConnection();
    JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
    stmt.setObject(1, (short) 123, Types.INTEGER);
    ParameterizedSparqlString pss = stmt.getParameterizedString();
    Assert.assertTrue(pss.toString().contains("123"));
    stmt.close();
    conn.close();
}
Also used : ParameterizedSparqlString(org.apache.jena.query.ParameterizedSparqlString) JenaConnection(org.apache.jena.jdbc.connections.JenaConnection) Test(org.junit.Test)

Example 69 with JenaConnection

use of org.apache.jena.jdbc.connections.JenaConnection in project jena by apache.

the class AbstractJenaStatementTests method statement_closed_results_02.

/**
     * Tests error cases for trying to access results on closed statements
     * 
     * @throws SQLException
     */
@Test(expected = SQLException.class)
public void statement_closed_results_02() throws SQLException {
    JenaConnection conn = this.getConnection();
    Statement stmt = conn.createStatement();
    stmt.close();
    try {
        stmt.getMoreResults();
    } finally {
        conn.close();
    }
}
Also used : JenaConnection(org.apache.jena.jdbc.connections.JenaConnection) Test(org.junit.Test)

Example 70 with JenaConnection

use of org.apache.jena.jdbc.connections.JenaConnection in project jena by apache.

the class AbstractJenaStatementTests method prepared_statement_setters_30.

/**
     * Tests that the various set methods of {@link JenaPreparedStatement}
     * function correctly
     * 
     * @throws SQLException
     */
@Test
public void prepared_statement_setters_30() throws SQLException {
    JenaConnection conn = this.getConnection();
    JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
    stmt.setByte(1, (byte) 123);
    ParameterizedSparqlString pss = stmt.getParameterizedString();
    Assert.assertTrue(pss.toString().contains("123"));
    Assert.assertTrue(pss.toString().contains(XSDDatatype.XSDbyte.getURI()));
    stmt.close();
    conn.close();
}
Also used : ParameterizedSparqlString(org.apache.jena.query.ParameterizedSparqlString) JenaConnection(org.apache.jena.jdbc.connections.JenaConnection) Test(org.junit.Test)

Aggregations

JenaConnection (org.apache.jena.jdbc.connections.JenaConnection)199 Test (org.junit.Test)198 ParameterizedSparqlString (org.apache.jena.query.ParameterizedSparqlString)79 CommandPreProcessor (org.apache.jena.jdbc.preprocessing.CommandPreProcessor)11 Calendar (java.util.Calendar)8 Properties (java.util.Properties)7 ResultsEcho (org.apache.jena.jdbc.postprocessing.ResultsEcho)7 Echo (org.apache.jena.jdbc.preprocessing.Echo)7 File (java.io.File)6 FileWriter (java.io.FileWriter)5 URL (java.net.URL)3 URI (java.net.URI)2 DatabaseMetaData (java.sql.DatabaseMetaData)2 ResultsPostProcessor (org.apache.jena.jdbc.postprocessing.ResultsPostProcessor)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1