AJAX Tricks and Prototype

Netbeans and Derby and Ajax

  1. Add the derby.jar library to your project. It was installed under glassfish-v2/javadb/lib.
  2. Here is sample code for the connection:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package edu.sc.cse;
    
    import org.apache.derby.jdbc.*;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    
    public class DatabaseConnector {
    
        public static Connection getConnection() {
            Connection con = null;
            String driver = "org.apache.derby.jdbc.EmbeddedDriver";
            try {
                Class.forName(driver).newInstance();
    
            } catch (Exception e) {
                System.out.println("Failed to load mySQL driver.");
                return null;
            }
            try {
                //AJAX is the database name. 
                //This is for empty username and password
                //Otherwise append ?username=jmvidal&password=usc
                con = DriverManager.getConnection("jdbc:derby://localhost:1527/AJAX");
    
              } catch (Exception e) {
                  e.printStackTrace();
              }
              return con;
          }
    }
    
    
  3. To import or export a whole table, like zipcodes.del use:
    /*To import my zipcodes.del table */
    CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE
    (null,'ZIPCODES','/full-path-name/zipcodes.del',null,null,null,0)
    
    
    /* To export a table */
    CALL SYSCS_UTIL.SYSCS_EXPORT_TABLE
    (null,'ZIPCODES','/full-path-name/zipcodes.del',null,null,null)
    
    
    
    
  4. To delete all rows use delete from "TABLENAME"
  5. To insert use INSERT INTO TABLE (USERNAME,PASSWORD) VALUES ('jmvidal','usc')
  6. When building statments in JDBC, do not add a ; at the end.

José M. Vidal .

6 of 16