/* This is a sample plugin that illustrates using PluginInteropt with the DatabasePlugin. To use this example, you will first need to get the DatabasePlugin example working. Once that's working, you can simply add this to your configuration.xml file in the plugins section: UseDatabasePlugin Script Server path\to\UseDatabasePlugin.as Remember to change the entry to point to the appropriate location on your machine. Once that's complete, you can simply call the plugin directly. It will trace() out information to show you that it worked properly. -=-=- If you want to use ElectroServer with other databases then you will need to get the appropriate driver, create the connection string, and configure the database plugin. You can find a list of available JDBC drivers here: http://servlet.java.sun.com/products/jdbc/drivers For all intents and purposes, there are JDBC drivers available for any major database. Often, the drivers are created by the database manufacturer themselves and come with the database installer. In the configuration.xml file, you will need to associate a drivername with your new database connection. The name for Access is: sun.jdbc.odbc.JdbcOdbcDriver For MySql (if you use the Connector J drivers, downloadable at http://dev.mysql.com/downloads/connector/j/3.0.html) it's: com.mysql.jdbc.Driver Once you have that entry set up, you need to specify the connection string. This is going to be specific to your driver. Check the documentation for examples. An example for Access would be: jdbc:odbc: For MySql: jdbc:mysql:///?user=&password= ie: jdbc:mysql://localhost/test?user=monty&password=greatsqldb */ function pluginInit(hash) { //This method is called when the plugin is initialized } function pluginRequest(hash) { // Get the user from the passed in hashmap var caller = hash.get("ExecutingUserName"); // Get access to the plugin helper var helper = Plugin.getPluginHelper(); // Set up the plugin name to call var pluginName = "DatabasePlugin"; // Build the hashmap for the select statement var selectHash = new java.util.HashMap(); selectHash.put("PoolName", "TestDB"); selectHash.put("Method", "ExecuteQuery"); selectHash.put("Statement", "Select * from Test"); // Execute the select statement and return the results var selectResults = helper.callRemotePlugin(pluginName, selectHash); // Display the results trace("Executed \"select * from test\""); trace("Current table contents"); dumpResultsOut(selectResults); // Build the hashmap for the insert statement var insertHash = new java.util.HashMap(); insertHash.put("PoolName", "TestDB"); insertHash.put("Method", "ExecuteUpdate"); insertHash.put("Statement", "Insert into Test (Name) values ('test name')"); // Execute the insert statement helper.callRemotePlugin(pluginName, insertHash); trace("\nExecuted \"Insert into Test (Name) values ('test name')"); // Execute the select statement and return the results selectResults = helper.callRemotePlugin(pluginName, selectHash); // Display the results trace("\nExecuted \"select * from test\""); trace("New table contents"); dumpResultsOut(selectResults); } function dumpResultsOut(returnedHash) { // Get the status var status = returnedHash.get("Status"); trace("Query Status: " + status); // Get the results from the hash var resultsHash = returnedHash.get("Results"); // Get the two columns of data var testIdList = resultsHash.get("TestID"); var nameList = resultsHash.get("Name"); // Prime the output var output = ""; // Loop over them for(var i = 0; i < testIdList.size(); i++) { var currentId = testIdList.get(i); var currentName = nameList.get(i); output += currentId + "\t" + currentName + "\n"; } // Get access to the plugin helper var helper = Plugin.getPluginHelper(); // Print out the results trace(output); } function returnToUser(value, caller) { var variables = new Object(); variables.result = value; var action = "CalculationResult"; server.sendMessage("private", [caller], action, variables); }