InstantDB Project
About InstantDB
Project Mail Lists
Short History
Reporting Bugs
Screen Shots
3rd Party Examples
FAQs

Software
Downloads
Documentation
CVS Repositories
Roadmap
License

About Enhydra.org
Who We Are
News, Articles & Events
Getting Involved
Contact Us

Community
Demos
Contributions
Resources
Case Studies
On The Edge! -NEW-
Commercial Vendors


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

InstantDB: Escape Character


I need to set up InstantDB so that it will not respond to its escape
character "\".

So far I have tried
	-setting   Statement.setEscapeProcessing(false);
	-using a prepared statement while setting the InstantDB property
"prepareIgnoresEscapes=1"

Alas, this doesn't seem to work.  The following are the properties I am
using in my InstantDB properties file, and the test class I created to
isolate the problem.  Look at the log method.
  Thanks in advance!
    -Matt Paulin



dateTimeFormat=yyyy-mm-dd hh\:nn\:ss.lll
traceConsole=0
prepareIgnoresEscapes=1
transLevel=0
traceFile=./trace.log
recoveryPolicy=1
tablePath=./tables
systemPath=./system
indexPath=./indexes
relativeToProperties=1
tmpPath=./tmp


import java.io.File;
import java.io.IOException;
import java.lang.NumberFormatException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.Vector;
import org.enhydra.instantdb.jdbc.idbDriver;
import sun.jdbc.odbc.JdbcOdbcDriver;

/**
 * Used to figure out instantDB issue
 * @author Matt Paulin
 * @version 1.0
 */

public class InstantDBExperiment {

    /**
     * The table name for the Entries in the database
     */
    private static final String TABLE = "Data";

    /**
     * The column name for the test data
     */
    static final String DATA_NAME = "TestData";

    /**
     * JDBC connection to the database
     */
    private Connection con;

    /**
     * All of the drivers used by JDBC to load the InstandDB
     */
    private String[] instantDBDrivers =
{"org.enhydra.instantdb.jdbc.idbDriver",
                                         "sun.jdbc.odbc.JdbcOdbcDriver"};

    /**
     * Creates the DB
     */
    public InstantDBExperiment(File loggingDir) {
        super();

        for (int i=0; i< instantDBDrivers.length; i++) {
            try {
                Class.forName (instantDBDrivers[i]).newInstance();
            } catch (IllegalAccessException e) {
                System.out.println("Cannot Access DB Drivers "+
e.toString());
            } catch (ClassNotFoundException e) {
                System.out.println("Cannot Find DB Drivers "+ e.toString());
            } catch (InstantiationException e) {
                System.out.println("Cannot Load DB Drivers "+ e.toString());
            }
        }

        String dbName = "jdbc:idb:"+
                        loggingDir.getAbsolutePath()+
                        java.io.File.separator+
                        "InstantDB.prp";

        try{
            con = DriverManager.getConnection(dbName);
        }catch(SQLException e) {
            System.out.println("Cannot connect to DB "+ e.toString());
        }

        setupDb();
    }


    /**
     * Logs an data to the database.
     */
    public void log(String data) {

        String sqlStatement = "INSERT INTO " + TABLE + " VALUES ("+
                                  "'" + data + "')";

        try{
            System.out.println("Statement is "+ sqlStatement);
//                Statement stmt = con.createStatement();
            PreparedStatement stmt = con.prepareStatement(sqlStatement);
            stmt.setEscapeProcessing(false);

            //run the sql statement
            stmt.execute(sqlStatement);

            stmt.close();
        }catch(SQLException e) {
            System.out.println("Cannot Store Data "+ e.toString());
        }
    }

    /**
     * Queries and prints everything in the db
     */
    public void printQuery() {
        ResultSet rs;
        String sqlStatement = "Select * from "+ TABLE;
        try{
            Statement stmt = con.createStatement();
            rs = stmt.executeQuery(sqlStatement);

            stmt.close();

            while(rs.next()) {
                System.out.println(rs.getString(DATA_NAME));
            }
        }catch(Exception e) {
            System.out.println("Cannot Query Database "+ e.toString());
        }
    }

    /**
     * Sets up the tables in the database.
     */
    public void setupDb() {
        String createTableSQL;

        try{
            createTableSQL = "CREATE TABLE "+ TABLE+ " ( "+
                              DATA_NAME + " CHAR(" + 1000 + ")" +
                              ")";

            Statement stmt = con.createStatement();

            //Ok now create the table
            stmt.execute(createTableSQL);
            stmt.close();
        }catch(SQLException e) {
            //Expected Behavior for existing table

        }
    }

    /**
     * Tells the database to shut down and closes the connection.
     */
    public void shutdown(){
        if(con != null) {
            try{
                con.close();
            }catch(SQLException e) {
                System.out.println("CorruptDBConnection "+ e.toString());
            }
        }
    }

    /**
     * Resets the database.
     */
    public void resetDB() {
        try{
            //Remove everything from the db
            Statement stmt = con.createStatement();
            stmt.execute("DROP TABLE "+TABLE);
            stmt.close();

            //resetup the db
            this.setupDb();
        }catch(SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * Creates the test class
     */
    public static void main(String[] args) {
        InstantDBExperiment dbtest1 = new InstantDBExperiment(new
File("./experiment"));
        dbtest1.resetDB();
        dbtest1.log("Test1");
        dbtest1.log("Test2");
        dbtest1.log("\\Test3");
        dbtest1.log("Test4");
        dbtest1.printQuery();
    }
}



-----------------------------------------------------------------------------
To unsubscribe from this mailing list, send email to majordomo@enhydra.org
with the text "unsubscribe instantdb" in the body of the email.
If you have other questions regarding this mailing list, send email to
the list admin at owner-instantdb@enhydra.org.