Is it possible to run a prepared statement in jdbc that uses with clause in a single sql statement something like this
public class JdbcSample {
private static String jdbcUrl = "jdbc:demoapp:v2://localhost:8080";
private static List<ResultSet> resultSets = new ArrayList<>();
public static void main(String[] args) throws Exception {
System.out.println("Starting the app.");
Connection connection = getConnection();
testPreparedQuery(connection);
}
public static void testPreparedQuery(Connection connection) throws SQLException {
String preparedSql = "with temp as (select * from nation where col1 = ?) select * from temp";
PreparedStatement pStmt = connection.prepareStatement(preparedSql);
pStmt.setString(1,"india");
ResultSet resultSet = pStmt.executeQuery();
resultSet.next();
}
public static Connection getConnection() throws SQLException {
AsgardDriver.registerDriver();
Driver driver = DriverManager.getDriver(jdbcUrl);
Properties props = new Properties();
Connection connection = driver.connect(jdbcUrl, props);
return connection;
}
}
when I tried to run this its throwing java.lang.NullPointerException. I tried multiple sqls none of them works. I went through docs but didn't find any evidence about whether we can use with clause or not in the prepared statement.