Java: Prepare a statement without a connection
I'm guessing that until you've got a sql connection, the parser won't know what rules to apply. I'm guessing that it's actually the SQL driver or even server that's compiling the sql statement.
Assuming your sql is simple enough, then how about using a cheap connection, like, say a sqlite connection.
SQLite will create a new database on the fly if the database you're attempting to connect to does not exist.
public Connection connectToDatabase() {// connect to the database (creates new if not found)try { Class.forName("org.sqlite.JDBC"); conn = DriverManager.getConnection("jdbc:sqlite:mydatabase.db"); // initialise the tables if necessary this.createDatabase(conn);}catch (java.lang.ClassNotFoundException e) { System.out.println(e.getMessage());}catch (java.sql.SQLException e) { System.out.println(e.getMessage());}return conn;}
Not really. Preparing a statement in most cases means that it will be compiled by DBMS which is "hard" without connection.
http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html