I18njdbc - a JDBC driver for property files |
About I18njdbc is a simple read and write JDBC driver that uses property files as database tables. |
How is it used The I18njdbc driver is used just like any other JDBC driver. The i18njdbc.jar file should be included in your application's classpath. Folder where are placed these property files is database. These tables must have ONLY two columns. First column contains keys and second one contains values related with these keys. Values in key column are unique. This is the example of property file used by i18njdbc driver: firstname18n=vorname secondname18n=familienname new18n=erzeugen edit18n=bearbeiten In this example key column contains: firstname18n, secondname18n, new18n, edit18n.Values related with these keys are in second column that contains:vorname, familiename, erzeugen, bearbeiten. The driver class is org.webdocwf.util.i18njdbc.I18nDriver The connection URL is jdbc:webdocwf:i18n:i18ndir, where i18ndir is the directory in which the .property files are found. This example code shows how the driver is used. import java.sql.*; public class DemoDriver { public static void main(String[] args) { try { // load the driver into memory Class.forName("org.webdocwf.util.i18njdbc.I18nDriver"); // create a connection. The first command line parameter is assumed to // be the directory in which the .property files are held Connection conn = DriverManager.getConnection("jdbc:webdocwf:i18n:" + args[0] ); // create a Statement object to execute the query with Statement stmt = conn.createStatement(); // Select the name and value columns from sample.property ResultSet results = stmt.executeQuery("SELECT name,value FROM sample"); // dump out the results while (results.next()) { System.out.println("name= " + results.getString("name") + " value= " + results.getString("value")); } // clean up results.close(); stmt.close(); // I18njdbc Driver also support PreparedStatements. // PreparedStatement.setString() are method that can be used. // // create PreparedStatement PreparedStatement pstmt = conn.prepareStatement("INSERT INTO sample ( name, value ) VALUES (?, ?) "); pstmt.setString(1, "1"); pstmt.setString(2, "somevalue" ); pstmt.executeUpdate(); pstmt.clearParameters(); pstmt.close(); conn.close(); } catch(Exception e) { System.out.println("Oops-> " + e); } } } |
Advanced Options The driver also supports a number of parameters that change the default behavior of the driver. These properties are:
It supports CREATE, SELECT, INSERT, UPDATE, DELETE statements. Also support WHERE clause but without OR,AND,... operands. These are sample statements: CREATE test(name VARCHAR(250), value VARCHAR(250)) Following example code shows how these properties are used. ... Properties props = new java.util.Properties(); props.put("nameColumn","keys"); // column name for column with keys props.put("valueColumn","data"); // column name for column with values for related keys props.put("fileExtension",".txt"); // file extension is .txt props.put("charset","ISO-8859-2"); // file encoding is "ISO-8859-2" props.put("create","true"); // driver will create directory(s) Connection conn = Drivermanager.getConnection("jdbc:webdocwf:i18n:" + args[0],props) ... Also, this parameters can be passed when creating connection on the other way : Connection conn = DriverManager.getConnection("jdbc:webdocwf:i18n:databasename;fileExtension=.txt;create=true") |