Example #1
0
 static void openDB() {
   System.out.println("Username: "******"Password: "******":");
   User u = new User(usernameSQL, passwordSQL.toCharArray());
   flags.openDatabase(u);
 }
Example #2
0
  public static void main(String args[]) {
    UniJava uJava = new UniJava();
    System.out.println("Version number = " + uJava.getVersionNumber());
    System.out.println("Max # Sessions = " + uJava.getMaxSessions());

    try {
      UniSession uSession = uJava.openSession();
      System.out.println("openSession is successful");

      try {
        xTmp = inputStringCheck("Choose DataSourceType: 1) UniData (Default) 2) UniVerse: ");
        // vTmp = getInt("Choose DataSourceType: 1) UniData (Default) 2) UniVerse: ");

      } catch (java.io.IOException e) {
        printMsg("DataBaseType Error !");
      }

      if (xTmp.length() == 0) {
        vTmp = 1;
      } else {
        vTmp = Integer.parseInt(xTmp);
      }

      if (vTmp == 2) {
        xDataSourceType = "UNIVERSE";
        xServiceName = "uvcs";
        xHostName = "Localhost";
        xAccount = "HS.SALES";
        xFile = "STATES";
        xRecordID = "CO";
      } else {
        xDataSourceType = "UNIDATA";
        xServiceName = "udcs";
        xHostName = "Localhost";
        xAccount = "demo";
        xFile = "STATES";
        xRecordID = "CO";
      }

      try {
        uSession.setDataSourceType(xDataSourceType);
      } catch (UniConnectionException e) {
        printMsg("setDataSourceType to UNIDATA/UNIVERSE failed");
      }

      try {
        xTmp =
            inputString(
                "Please input the UniObject Service Name (Default " + xServiceName + ") : ");
      } catch (java.io.IOException e) {
        printMsg("UniObject Service Name Error !");
      }

      if (xTmp.length() != 0) {
        xServiceName = xTmp;
      }

      try {
        xTmp = inputString("Please input the HostName (Default " + xHostName + ") : ");
      } catch (java.io.IOException e) {
        printMsg("HostName Error !");
      }

      if (xTmp.length() != 0) {
        xHostName = xTmp;
      }

      try {
        xUserName = inputString("Please input the UserName: "******"UserName Error !");
      }

      char pwdx[];
      try {
        // xPassword = getParameter("Password");
        // xPassword = inputString("Please input the Password: "******"Please input the password: "******"Password Error !");
      }

      try {
        printMsg("Default account " + xAccount + " !");
        xTmp = inputString("Please input the Account: ");
      } catch (java.io.IOException e) {
        printMsg("Account Name Error !");
      }

      if (xTmp.length() != 0) {
        xAccount = xTmp;
      }

      uSession.setConnectionString(xServiceName);
      uSession.setHostName(xHostName);
      uSession.setUserName(xUserName);
      uSession.setPassword(xPassword);
      uSession.setAccountPath(xAccount);

      printMsg("Server Name =" + xHostName);
      uSession.connect();

      try {
        printMsg("Default file (" + xFile + ") !");
        xTmp = inputString("Please input the File Name: ");
      } catch (java.io.IOException e) {
        printMsg("File Name Error !");
      }

      if (xTmp.length() != 0) {
        xFile = xTmp;
      }

      UniFile uojFile = uSession.open(xFile);
      System.out.println("\nThe " + xFile + " file was opened successfully");

      // Read entire CO record
      try {
        printMsg("Default Record ID (" + xRecordID + ") !");
        xTmp = inputString("Please input the Record ID: ");
      } catch (java.io.IOException e) {
        printMsg("Record ID Error !");
      }
      if (xTmp.length() != 0) {
        xRecordID = xTmp;
      }

      // Extract record value based on the record ID
      try {
        UniString custRec = uojFile.read(xRecordID);
        UniDynArray custArray = new UniDynArray(custRec);
        System.out.println("custArray Object: " + custArray.toString());
      } catch (UniFileException e) {
        System.out.println("error: " + e);
      }

      // catch ( UniStringException e ){
      //	System.out.println("error: "+e+" CODE = "+e.getErrorCode());
      // }

      // close UniSession & UniJava
      uojFile.close();
      uSession.disconnect();
      uJava.closeSession(uSession);
      System.out.println("\n\t*--- End of Test ---*\n");
    } catch (UniSessionException e) {
      System.out.println("error: " + e + " CODE = " + e.getErrorCode());
    } catch (UniFileException e) {
      System.out.println("Error CODE = " + e.getErrorCode() + " error: " + e);
    }
  }