• Welcome to KonaKart Community Forum. Please login or sign up.
 

Import Customer List

Started by bubba64, October 26, 2009, 04:36:49 am

Previous topic - Next topic

bubba64

Hi Konakart folks. I am trying to import customer contacts into the konakart database via a JDBC connection and the API example provided for Registering a customer. I keep getting the error about "Konakartadmin.properties" file not found in the class path. How should I specify the connection properties for this simple app (without putting the file in the classpath)?

I am loading customer information from an access database into the konakart database on a local machine to test out the process. Is there a more simple way to get this accomplished???? Here is what I have been trying (just a simple java application to communicate with the API library):

import java.sql.*;
import com.konakartadmin.app.*;
import com.konakartadmin.appif.*;

public class Main
{ protected static KKAdminIf eng;
  private static String DEFAULT_USERNAME = "<mykonakartusername>";
  private static String DEFAULT_PASSWORD = "<mykonakartpassword>";
  protected static String sessionId;

  public static void main(String[] args)
  { starterUp();
  }
  private static void starterUp()
  { try
    { init();
    }
    catch(Exception e)
    { System.out.println("StarterUp error: "+e);
    }
    loadMergeRecords();   
  }
  private static void loadMergeRecords()
  { Connection con = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try
    { con = getConnection();
      statement = con.prepareStatement(
      "SELECT * FROM <Access Table>");
      rs = statement.executeQuery();
      while (rs.next())
      { AdminCustomerRegistration acr = new AdminCustomerRegistration();
        //required stuff
        acr.setGender("m");
        acr.setFirstName(rs.getString("FirstName"));
        acr.setLastName(rs.getString("LastName"));
        acr.setEmailAddr(rs.getString("Email"));
        acr.setStreetAddress(rs.getString("Address1"));
        acr.setCity(rs.getString(rs.getString("City")));
        acr.setState(rs.getString("State"));
        acr.setPostcode(rs.getString("Zip"));
        acr.setTelephoneNumber(rs.getString("Phone"));
        acr.setPassword("12345");
        acr.setDontEncryptPassword(false);
        acr.setBirthDate(new java.util.Date());
        //optional
        acr.setCountryId(223);//US
        int custId  = eng.registerCustomer(sessionId, acr);
        System.out.println("Id of the new customer = " + custId);

        // Read the customer from the database
        AdminCustomer cust = eng.getCustomerForId(sessionId, custId);
        if (cust != null)
          System.out.println(cust.toString());
        else
          System.out.println("The customer could not be read from the DB");
      } 
    }
    catch (Exception e)
    { e.printStackTrace();
    }
    finally
    { closeConnections(rs, statement, con, "loadMergeRecords");
    }
  }
  static protected void init() throws ClassNotFoundException, InstantiationException, IllegalAccessException, KKAdminException
  { Class<?> engineClass = Class.forName("com.konakartadmin.bl.KKAdmin");
    eng = (KKAdminIf) engineClass.newInstance();
    sessionId = eng.login(DEFAULT_USERNAME, DEFAULT_PASSWORD);
  }
  private static Connection getConnection() throws Exception
  { String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:odbc:<system dsn database>";
    String username = "";//none needed
    String password = "";//none needed
    Class.forName(driver);
    return DriverManager.getConnection(url, username, password);
  }
  public static void closeConnections(ResultSet rs, PreparedStatement statement, Connection con, String method)
  { try
    { if (rs != null)
        rs.close();
      if (statement != null)
        statement.close();
      if (con != null)
        con.close();
      rs = null;
      statement = null;
      con = null;
    }
    catch (Exception e)
    { System.out.println("Error closing connection in " + method + ": " + e);
    }
  }
}

greg


bubba64

I ended up doing just that. I use netbeans and made two libraries consisting of two different 'konakartadmin.properties' files (one for local test database and one for the live database). My reasoning was to be able to test all database changes to a local 'test' database and then do the real thing on the live database. My original plan was to simply pass arguments to the main to switch between different connections to databases.

Simple enough now, using two different netbeans build scripts using the two different libraries (one library for a local connection properties file, and the other build using the properties file for the live database).

Thank you for the response.