Need Help Improving Memory Use of a Binary Data Insert

I am using the following code to insert binary data from an InputStream into a database.
It seems to be very memory inefficient. It works fine for small files. But for large files it really causes memory issues.
Imagine this coming from a 22mb file upload. This method first copies 22megs of data to an ArrayList. It then copies the data to an array. It then creates another array to store the bytes. Finally it inserts the data to the database.
Is there another way I can get data into a format that the setBytes() method can accept without using so much memory?
        * Inserts Binary Database into the Database
       private void insertData(InputStream stream){
         ConnectionPool pool = (ConnectionPool)properties.getProperty("zeusportal.connectionpool");
         Connection conn = null;
         BufferedReader in = new BufferedReader(new InputStreamReader(stream));
         try{
           byte[] byteArray;
           int streamlength = 0;
           int value;
              //Read Data Into Arraylist
           ArrayList list = new ArrayList();
           while((value = stream.read()) != -1){
             list.add(new Integer(value));
           Object data[] = list.toArray();
              //Create Byte Array to store bytes
           byteArray = new byte[data.length];
              //Copy Data from ArrayList into Byte Array
           for(int iCounter = 0; iCounter < byteArray.length; ++iCounter){
             Integer curr = (Integer)data[iCounter];
             byteArray[iCounter] = curr.byteValue();
              //Retrieve Connection
           conn = pool.getConnection();
           conn.setAutoCommit(false);
           PreparedStatement pstmt = conn.prepareStatement("INSERT INTO table (video_name, video_description, video_contenttype, video_content, upload_date, objecttype, objectid) values(?, ?, ?, ?, ?, ?, ?)");
              //Insert Data Attributes into PreparedStatement
           pstmt.setString(1, this.name);
           pstmt.setString(2, this.description);
           pstmt.setString(3, this.contenttype);
           pstmt.setBytes(4, byteArray);
           pstmt.setInt(6, objectType);
           pstmt.setLong(7, objectID);
           this.date = new java.util.Date();
           pstmt.setLong(5, date.getTime() / 1000L);
           pstmt.execute();
           pstmt.close();
           conn.commit();
           conn.setAutoCommit(true);
         catch(SQLException sqle){
           throw new RuntimeException(sqle);
         catch(IOException ioe){
           throw new RuntimeException(ioe);
         finally{
           if(conn != null){
             pool.releaseConnection(conn);
         return;
       }//insertData

I have tried storing the data in a temp file and then retrieved the length of the file. That however didn't work as the data was corrupted for anything but the smallest files.
        * Inserts the data into the database
       private void insertData(InputStream stream){
         ConnectionPool pool = (ConnectionPool)properties.getProperty("zeusportal.connectionpool");
         Connection conn = null;
         BufferedInputStream in = new BufferedInputStream(stream);
         try{
                  //Create Temporary File to Store Binary Data
            File file = File.createTempFile(Math.random()+"", ".tmp");
                  //Create a writer to write to the Temp File
            OutputStream writer = new FileOutputStream(file);
                  writer = new BufferedOutputStream(writer);
           int value;
              //Copy Data to Temp File
           while((value = in.read()) != -1){
             writer.write(value);
           writer.flush();
           writer.close();
              //Read new InputStream from Temp File
           stream = new FileInputStream(file);
           //Retrieve Connection
           conn = pool.getConnection();
           conn.setAutoCommit(false);
              //Inset Data to the database
           PreparedStatement pstmt = conn.prepareStatement("INSERT INTO zeusportalvideos (video_name, video_description, video_contenttype, video_content, upload_date, objecttype, objectid) values(?, ?, ?, ?, ?, ?, ?)");
           pstmt.setString(1, this.name);
           pstmt.setString(2, this.description);
           pstmt.setString(3, this.contenttype);
           pstmt.setBinaryStream(4, stream, (int) file.length());
           pstmt.setInt(6, objectType);
           pstmt.setLong(7, objectID);
           this.date = new java.util.Date();
           pstmt.setLong(5, date.getTime() / 1000L);
           pstmt.execute();
           pstmt.close();
           stream.close();
           file.delete();
           conn.commit();
           conn.setAutoCommit(true);
         catch(SQLException sqle){
           throw new RuntimeException(sqle);
        catch(IOException ioe){
           throw new RuntimeException(ioe);
         finally{
           if(conn != null){
             pool.releaseConnection(conn);
         return;
       }//insertData

Similar Messages

  • Hello.  I need help.  I use Photoshop Elements 10 on my MAC but it no longer reads discs.  Can I download it from the internet with my original package serial number?

    Hello.  I need help.  I use Photoshop Elements 10 on my MAC but it no longer reads discs.  Can I download it from the internet with my original package serial number?  thanks

    Yes, from here:
    Download Photoshop Elements products | 13, 12, 11, 10

  • Need help how to use itunes card to download music

    Need help how to use itunes card to download music

    If you want to add the iTunes card to your account, then in the iTunes app on the iPad you should be able to scroll to the bottom of the Music tab and there should be a Redeem button - there is more info here : http://support.apple.com/kb/HT1574

  • I have lost the use of my extension pannels, and need help recovering the use. I get a message that extensions failed to load. Why?

    I have lost the use of my extension pannels, and need help recovering the use. I get a message that extensions failed to load. Why?

    I've had that before when on a really slow Internet connection.

  • Hii i need help i cannot use my apple id for download on app store because they say i need to verify my account but i don't know how so please somebody can help me? i try to resset my password but that don't help

    hii i need help i cannot use my apple id for download on app store because they say i need to verify my account but i don't know how so please somebody can help me? i try to resset my password but that don't help

    is it asking for ur security questions?

  • Need help trying to use close button and i really like to know why it off

    need help trying to use close button and i really like to know why it off

    And in English? You need to explain better.
    Mylenium

  • This is detailed: I lost my touch pad scroll ability on my desktop when I installed Firefox, I am having a terrible time trying to sync my new Android tablet to my desktop, my desktop Firefox is acting very strangly (I need help trying to use it)

    My Vista Home Premium desktop has not used Firefox for a long time. I just loaded it as well as on my Honeycomb Android. The statement that I made pretty much says what my problem is. I can use both of them at the same time and use a router with the air Verizon card installed.
    I'll repeat my question: This is detailed: I lost my touch pad scroll ability on my desktop when I installed Firefox, I am having a terrible time trying to sync my new Android tablet to my desktop, my desktop Firefox is acting very strangely (I need help trying to use it)

    My Vista Home Premium desktop has not used Firefox for a long time. I just loaded it as well as on my Honeycomb Android. The statement that I made pretty much says what my problem is. I can use both of them at the same time and use a router with the air Verizon card installed.
    I'll repeat my question: This is detailed: I lost my touch pad scroll ability on my desktop when I installed Firefox, I am having a terrible time trying to sync my new Android tablet to my desktop, my desktop Firefox is acting very strangely (I need help trying to use it)

  • I bought apps from apps store,my money was taken and den I downloaded the pass buh 2 didn't work .it told me iTunes failed to install app,the apps were the dark knight rises(batman) and asphalt 7 I need help plss am using iPad 2

    bought apps from apps store,my money was taken and den I downloaded the apps buh 2 didn't work .it told me iTunes failed to install app,the apps are the dark knight rises(batman) and asphalt 7 I need help plss am using iPad 2

    Although iTune terms says that all sales are final. You can try explaining to get a refund.
    http://www.apple.com/support/itunes/contact/

  • DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file

    Hi
    DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file
    Two main
    sections:
    1)     
    Perform
    write and read operations to and fro different spread sheet files, such that
    each file have a single row of 32bits different binary data (analogous to 1D
    array) where the left most bit is the MSB. I don’t want to manually enter the
    32 bits binary data, I want the data written or read just by opening a file
    name saves with the intended data.
          2)     
    And
    by using test patterns implemented using the digital pattern generator or  build digital data functions or otherwise, I need to
    ensure that the     
                binary data written to a spreadsheet file or any supported file type
    then through the NI-USB 6509 is same as the data read.
    I’m aware I can’t use the simulated
    device to read data written to any port but if the write part of the vi works I
    ‘m sure the read part will work on the physical device which I’ll buy later.
    My Plan
    of action
    I’ve
    created a basic write/read file task and a write/read DAQ task for NI USB 6509
    and both combine in a while loop to form a progress VI which I’m confuse of how
    to proceed with the implementation.
    My
    greatest problem is to link both together with the correct functions or operators
    such that there are no syntax/execution errors and thus achieve my intended
    result.
    This
    project is one of my many assignments for my master thesis, so please i’ll
    appreciate every help as I’m not really efficient with LabVIEW programming but
    I prefer it because is fun and interesting if I get to know it.
    Currently I’m
    practicing with LabVIEW 8.6/NI DAQmx 8.8 Demo versions and NI USB 6509
    simulated device.
    Please see
    the attached file for my novice progress, thanks in
    advance for the support
    Rgds
    Paul
    Attachments:
    DIO_write_read DAQ from file.vi ‏17 KB

    What does your file look like?  The DAQmx write is expecting a single U32 value, not an array of I64. 
    Message Edited by vt92 on 09-16-2009 02:42 PM
    "There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal

  • What to use to store binary data in Java

    Hello,
    I have to read data stored as varbinary in the SQL database. What kind of class, data type I can use to store binary data from database?
    I need to store binary data finally in ByteBuffer.
    Please, help.
    Thank you!

    Unfortunately, when I am doing following I am getting an exception:
    ByteBuffer lUTF8BIN=ByteBuffer.allocate(6)
    byte [] lTempByteArray lTempByteArray = Recordset.getBytes(VarBinColumn);
    if (lUTF8BIN.remaining()>=lTempByteArray.length)
    lUTF8BIN.put(lTempByteArray);
    Exception is java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported data conversion

  • My ipod touch is in DFU mode 5g I need help, do not want to lose my data, please help in Spanish

    I need help, do not want to lose my data, PLEASE HELP IN SPANISH

    Una vez que el dispositivo está pidiendo ser restaurado con iTunes ... ya es demasiado tarde para salvar nada ... y usted debe continuar con la recuperación de ...
    Vea aquí> http://support.apple.com/kb/HT1808
    Es posible que tenga que probar más de una vez ... Asegúrese de seguir todos los pasos ...
    Tómese su tiempo ... Preste especial atención a los pasos 3 y 4.
    Para minimizar la pérdida ...
    Después de haber recuperado su dispositivo ...
    Re-sincronizar su contenido o restauración de la última copia de seguridad ...
    Restaurar desde copia de seguridad> http://support.apple.com/kb/ht1766
    Once the Device is asking to be Restored with iTunes... it is too late to save anything... and you must continue with the Recovery...
    See Here  >  http://support.apple.com/kb/HT1808
    You may need to try this More than Once...  Be sure to Follow ALL the Steps...
    Take your time... Pay particular attention to Steps 3 and 4.
    To minimise loss...
    After you have Recovered your Device...
    Re-Sync your Content or Restore from the most recent Backup...
    Restore from Backup  >  http://support.apple.com/kb/ht1766

  • Need help in FM used in IDOC

    Hi experts,
    Need help with IDOC. I'm creating 2 FM to process an existing idoc.
    first FM will use the data from idoc 1 to populate EDIDD for idoc 2.
    second FM will use the data from idoc 2 to populate EDIDD for idoc 3.
    when during processing, I encountered error message "No function module for input process code <second FM>".
    although i already link the FM to be used, why does FM 1 cannot call FM 2 directly?
    Thanks.

    In LSMW object attributes... give like this..
    Message Type         CREMAS                      Vendor master data distri
    Basic Type           CREMAS04                    Vendor master data distri
    Enhancement
    after that continue normal LSMW procedure.

  • Need help improve the code

    I have this file but I need to improve the code on some method. The methods are addNode, deleteNode, saveNode, findLader and are they anyway for me to iliminate the findsmallest method?
    here is the code
    import java.io.*;
    import java.util.LinkedList;
    import java.util.Stack;
    import javax.swing.*;
    public class Graph {
    private LinkedList graph;
    private BufferedReader inputFile;
    public Graph() {
    graph = new LinkedList();
    // read the words from the given file
    // create a GraphNode
    // Add the node to the graph
    public void createGraph(String fileName) throws IOException {
    inputFile = new BufferedReader(
    new InputStreamReader(new FileInputStream("word.txt")));
    // Convert the linkedlist to an array 'a'
    // sort the array 'a'
    // create a string from all elements in 'a'
    // return the string
    public String printGraph() {
    String output = new String();
    // will contain String objects
    // ... do some work with the list, adding, removing String objects
    String[] a = new String[graph.size()];
    graph.toArray(a);
    // now stringArray contains all the element from linkedList
    quickSort(a, 0, a.size() - 1);
    for(int i=0;i<a.length;++i)
    output = output + new String(a.toString())+"\n";
    return output;
    private static void quickSort(Comparable[] theArray,
    int first, int last) {
    // Sorts the items in an array into ascending order.
    // Precondition: theArray[first..last] is an array.
    // Postcondition: theArray[first..last] is sorted.
    // Calls: partition.
    int pivotIndex;
    if (first < last) {
    // create the partition: S1, Pivot, S2
    pivotIndex = partition(theArray, first, last);
    // sort regions S1 and S2
    quickSort(theArray, first, pivotIndex-1);
    quickSort(theArray, pivotIndex+1, last);
    } // end if
    } // end quickSort
    private static int partition(Comparable[] theArray,
    int first, int last) {
    // Partitions an array for quicksort.
    // Precondition: theArray[first..last] is an array;
    // first <= last.
    // Postcondition: Returns the index of the pivot element of
    // theArray[first..last]. Upon completion of the method,
    // this will be the index value lastS1 such that
    // S1 = theArray[first..lastS1-1] < pivot
    // theArray[lastS1] == pivot
    // S2 = theArray[lastS1+1..last] >= pivot
    // Calls: choosePivot.
    // tempItem is used to swap elements in the array
    Comparable tempItem;
    // place pivot in theArray[first]
    //choosePivot(theArray, first, last);
    Comparable pivot = theArray[first]; // reference pivot
    // initially, everything but pivot is in unknown
    int lastS1 = first; // index of last item in S1
    // move one item at a time until unknown region is empty
    for (int firstUnknown = first + 1; firstUnknown <= last;
    ++firstUnknown) {
    // Invariant: theArray[first+1..lastS1] < pivot
    // theArray[lastS1+1..firstUnknown-1] >= pivot
    // move item from unknown to proper region
    if (theArray[firstUnknown].compareTo(pivot) < 0) {
    // item from unknown belongs in S1
    ++lastS1;
    tempItem = theArray[firstUnknown];
    theArray[firstUnknown] = theArray[lastS1];
    theArray[lastS1] = tempItem;
    } // end if
    // else item from unknown belongs in S2
    } // end for
    // place pivot in proper position and mark its location
    tempItem = theArray[first];
    theArray[first] = theArray[lastS1];
    theArray[lastS1] = tempItem;
    return lastS1;
    } // end partition
    // Given a new word, add it to the graph
    public void addNode(String word) {
    GraphNode node = new GraphNode(word);
    if(graph.contains(node)){
    JOptionPane.showMessageDialog(null,"Duplicate Word, operation terminated");
    for(int i=0; i<graph.size(); ++i) {
    if(isAnEdge((String)(((GraphNode)graph.get(i)).getVertex()),(String)(node.getVertex()))) {
    EdgeNode e1 = new EdgeNode((String)node.getVertex(),1);
    EdgeNode e2 = new EdgeNode((String)((GraphNode)graph.get(i)).getVertex(),1);
    node.addEdge(e2);
    ((GraphNode)graph.get(i)).addEdge(e1);
    graph.add(node);
    public boolean deleteNode(String word) {
    GraphNode node = new GraphNode(word);
    EdgeNode n = new EdgeNode(word,1);
    if(!graph.contains(node)) {
    return false;
    else {
    for(int i=0; i<graph.size();++i) {
    ((GraphNode)graph.get(i)).getEdgeList().remove(n);
    graph.remove(node);
    return true;
    public void save(String fileName) {
    try {
    PrintWriter output = new PrintWriter(new FileWriter("word.txt"));
    for(int i=0; i< graph.size();++i) {
    output.println(((GraphNode)graph.get(i)).getVertex());
    output.close();
    catch (IOException e) {
    // given two word, find the ladder (using dijkstra's algorithm
    // create a string for the ladder and return it
    public String findLadder(String start,String end) {
    String ladder = new String();
    GraphNode sv = new GraphNode(start);
    GraphNode ev = new GraphNode(end);
    if(!graph.contains(sv)) {
    JOptionPane.showMessageDialog(null,start + " not in graph");
    return null;
    if(!graph.contains(ev)) {
    JOptionPane.showMessageDialog(null,end + " not in graph");
    return null;
    LinkedList distance = new LinkedList(((GraphNode)graph.get(graph.indexOf(sv))).getEdgeList());
    LinkedList visited = new LinkedList();
    visited.add(start);
    LinkedList path = new LinkedList();
    path.add(new PathNode(start,"****"));
    for(int i=0; i<distance.size();++i) {
    PathNode p = new PathNode((String)((EdgeNode)distance.get(i)).getKey(),start);
    path.add(p);
    while(!visited.contains(end)) {
    EdgeNode min = findSmallest(distance,visited);
    String v = (String)min.getVertex();
    if(v.equals("****"))
    return null;
    visited.add(v);
    // for(int i=0;i<graph.size();++i) {
    // String u = (String)(((GraphNode)(graph.get(i))).getVertex());
    GraphNode temp1 = new GraphNode(v);
    int index = graph.indexOf(temp1);
    LinkedList l = new LinkedList(((GraphNode)graph.get(index)).getEdgeList());
    for(int i=0;i<l.size();++i)
    String u = (String)(((EdgeNode)(l.get(i))).getVertex());
    if(!visited.contains(u)) {
    int du=999, dv=999, avu=999;
    dv = min.getCost();
    EdgeNode edge = new EdgeNode(u,1);
    if(distance.contains(edge)) {
    du = ((EdgeNode)(distance.get(distance.indexOf(edge)))).getCost();
    GraphNode temp = new GraphNode(v);
    GraphNode node = ((GraphNode)(graph.get(graph.indexOf(temp))));
    LinkedList edges = node.getEdgeList();
    if(edges.contains(edge)) {
    avu = ((EdgeNode)(edges.get(edges.indexOf(new EdgeNode(u,1))))).getCost();
    if( du > dv+avu) {
    if(du == 999) {
    distance.add(new EdgeNode(u,dv+avu));
    path.add(new PathNode(u,v));
    else {
    ((EdgeNode)(distance.get(distance.indexOf(u)))).setCost(dv+avu);
    ((PathNode)(path.get(path.indexOf(u)))).setEnd(v);
    if(!path.contains(new PathNode(end,"")))
    return null;
    LinkedList pathList = new LinkedList();
    for(int i=0;i<path.size();++i) {
    PathNode n = (PathNode)path.get(path.indexOf(new PathNode(end,"****")));
    if(n.getEnd().compareTo("****") != 0) {
    pathList.addFirst(end);
    n = (PathNode)path.get(path.indexOf(new PathNode(n.getEnd(),"****")));
    end = n.getStart();
    pathList.addFirst(start);
    for(int i=0;i<pathList.size()-1;++i) {
    ladder = ladder + ((String)(pathList.get(i))) + " --> ";
    ladder = ladder + ((String)(pathList.get(pathList.size()-1)));
    return ladder;
    private EdgeNode findSmallest(LinkedList distance, LinkedList visited) {
    EdgeNode min = new EdgeNode("****",999);
    for(int i=0;i<distance.size();++i) {
    String node = (String)(((EdgeNode)distance.get(i)).getVertex());
    if(!visited.contains(node)) {
    if(((EdgeNode)distance.get(i)).getCost()<min.getCost()) {
    min = (EdgeNode)distance.get(i);
    return min;
    // class that represents nodes inserted into path set
    private class PathNode {
    protected String sv;
    protected String ev;
    public PathNode(String s,String e) {
    sv = s;
    ev = e;
    public String getEnd() {
    return ev;
    public String getStart() {
    return sv;
    public void setEnd(String n) {
    ev = n;
    public boolean equals(Object o) {
    return this.sv.equals(((PathNode)o).sv);
    public String toString() {
    return "("+sv+":"+ev+")";
    thank you

    let me fix my misstake which was point out by some one in here and thank you ofr do so because I'm new at this.
    I have this file but I need to improve the code on some method. The methods are addNode, deleteNode, saveNode, findLader and are they anyway for me to iliminate the findsmallest method?
    here is the code
    import java.io.*;
    import java.util.LinkedList;
    import java.util.Stack;
    import javax.swing.*;
    public class Graph {
    private LinkedList graph;
    private BufferedReader inputFile;
    public Graph() {
    graph = new LinkedList();
    // read the words from the given file
    // create a GraphNode
    // Add the node to the graph
    public void createGraph(String fileName) throws IOException {
    inputFile = new BufferedReader(
    new InputStreamReader(new FileInputStream("word.txt")));
    // Convert the linkedlist to an array 'a'
    // sort the array 'a'
    // create a string from all elements in 'a'
    // return the string
    public String printGraph() {
    String output = new String();
    // will contain String objects
    // ... do some work with the list, adding, removing String objects
    String[] a = new String[graph.size()];
    graph.toArray(a);
    // now stringArray contains all the element from linkedList
    quickSort(a, 0, a.size() - 1);
    for(int i=0;i<a.length;++i)
    output = output + new String(a.toString())+"\n";
    return output;
    private static void quickSort(Comparable[] theArray,
    int first, int last) {
    // Sorts the items in an array into ascending order.
    // Precondition: theArray[first..last] is an array.
    // Postcondition: theArray[first..last] is sorted.
    // Calls: partition.
    int pivotIndex;
    if (first < last) {
    // create the partition: S1, Pivot, S2
    pivotIndex = partition(theArray, first, last);
    // sort regions S1 and S2
    quickSort(theArray, first, pivotIndex-1);
    quickSort(theArray, pivotIndex+1, last);
    } // end if
    } // end quickSort
    private static int partition(Comparable[] theArray,
    int first, int last) {
    // Partitions an array for quicksort.
    // Precondition: theArray[first..last] is an array;
    // first <= last.
    // Postcondition: Returns the index of the pivot element of
    // theArray[first..last]. Upon completion of the method,
    // this will be the index value lastS1 such that
    // S1 = theArray[first..lastS1-1] < pivot
    // theArray[lastS1] == pivot
    // S2 = theArray[lastS1+1..last] >= pivot
    // Calls: choosePivot.
    // tempItem is used to swap elements in the array
    Comparable tempItem;
    // place pivot in theArray[first]
    //choosePivot(theArray, first, last);
    Comparable pivot = theArray[first]; // reference pivot
    // initially, everything but pivot is in unknown
    int lastS1 = first; // index of last item in S1
    // move one item at a time until unknown region is empty
    for (int firstUnknown = first + 1; firstUnknown <= last;
    ++firstUnknown) {
    // Invariant: theArray[first+1..lastS1] < pivot
    // theArray[lastS1+1..firstUnknown-1] >= pivot
    // move item from unknown to proper region
    if (theArray[firstUnknown].compareTo(pivot) < 0) {
    // item from unknown belongs in S1
    ++lastS1;
    tempItem = theArray[firstUnknown];
    theArray[firstUnknown] = theArray[lastS1];
    theArray[lastS1] = tempItem;
    } // end if
    // else item from unknown belongs in S2
    } // end for
    // place pivot in proper position and mark its location
    tempItem = theArray[first];
    theArray[first] = theArray[lastS1];
    theArray[lastS1] = tempItem;
    return lastS1;
    } // end partition
    // Given a new word, add it to the graph
    public void addNode(String word) {
    GraphNode node = new GraphNode(word);
    if(graph.contains(node)){
    JOptionPane.showMessageDialog(null,"Duplicate Word, operation terminated");
    for(int i=0; i<graph.size(); ++i) {
    if(isAnEdge((String)(((GraphNode)graph.get(i)).getVertex()),(String)(node.getVertex()))) {
    EdgeNode e1 = new EdgeNode((String)node.getVertex(),1);
    EdgeNode e2 = new EdgeNode((String)((GraphNode)graph.get(i)).getVertex(),1);
    node.addEdge(e2);
    ((GraphNode)graph.get(i)).addEdge(e1);
    graph.add(node);
    public boolean deleteNode(String word) {
    GraphNode node = new GraphNode(word);
    EdgeNode n = new EdgeNode(word,1);
    if(!graph.contains(node)) {
    return false;
    else {
    for(int i=0; i<graph.size();++i) {
    ((GraphNode)graph.get(i)).getEdgeList().remove(n);
    graph.remove(node);
    return true;
    public void save(String fileName) {
    try {
    PrintWriter output = new PrintWriter(new FileWriter("word.txt"));
    for(int i=0; i< graph.size();++i) {
    output.println(((GraphNode)graph.get(i)).getVertex());
    output.close();
    catch (IOException e) {
    // given two word, find the ladder (using dijkstra's algorithm
    // create a string for the ladder and return it
    public String findLadder(String start,String end) {
    String ladder = new String();
    GraphNode sv = new GraphNode(start);
    GraphNode ev = new GraphNode(end);
    if(!graph.contains(sv)) {
    JOptionPane.showMessageDialog(null,start + " not in graph");
    return null;
    if(!graph.contains(ev)) {
    JOptionPane.showMessageDialog(null,end + " not in graph");
    return null;
    LinkedList distance = new LinkedList(((GraphNode)graph.get(graph.indexOf(sv))).getEdgeList());
    LinkedList visited = new LinkedList();
    visited.add(start);
    LinkedList path = new LinkedList();
    path.add(new PathNode(start,"****"));
    for(int i=0; i<distance.size();++i) {
    PathNode p = new PathNode((String)((EdgeNode)distance.get(i)).getKey(),start);
    path.add(p);
    while(!visited.contains(end)) {
    EdgeNode min = findSmallest(distance,visited);
    String v = (String)min.getVertex();
    if(v.equals("****"))
    return null;
    visited.add(v);
    // for(int i=0;i<graph.size();++i) {
    // String u = (String)(((GraphNode)(graph.get(i))).getVertex());
    GraphNode temp1 = new GraphNode(v);
    int index = graph.indexOf(temp1);
    LinkedList l = new LinkedList(((GraphNode)graph.get(index)).getEdgeList());
    for(int i=0;i<l.size();++i)
    String u = (String)(((EdgeNode)(l.get(i))).getVertex());
    if(!visited.contains(u)) {
    int du=999, dv=999, avu=999;
    dv = min.getCost();
    EdgeNode edge = new EdgeNode(u,1);
    if(distance.contains(edge)) {
    du = ((EdgeNode)(distance.get(distance.indexOf(edge)))).getCost();
    GraphNode temp = new GraphNode(v);
    GraphNode node = ((GraphNode)(graph.get(graph.indexOf(temp))));
    LinkedList edges = node.getEdgeList();
    if(edges.contains(edge)) {
    avu = ((EdgeNode)(edges.get(edges.indexOf(new EdgeNode(u,1))))).getCost();
    if( du > dv+avu) {
    if(du == 999) {
    distance.add(new EdgeNode(u,dv+avu));
    path.add(new PathNode(u,v));
    else {
    ((EdgeNode)(distance.get(distance.indexOf(u)))).setCost(dv+avu);
    ((PathNode)(path.get(path.indexOf(u)))).setEnd(v);
    if(!path.contains(new PathNode(end,"")))
    return null;
    LinkedList pathList = new LinkedList();
    for(int i=0;i<path.size();++i) {
    PathNode n = (PathNode)path.get(path.indexOf(new PathNode(end,"****")));
    if(n.getEnd().compareTo("****") != 0) {
    pathList.addFirst(end);
    n = (PathNode)path.get(path.indexOf(new PathNode(n.getEnd(),"****")));
    end = n.getStart();
    pathList.addFirst(start);
    for(int i=0;i<pathList.size()-1;++i) {
    ladder = ladder + ((String)(pathList.get(i))) + " --> ";
    ladder = ladder + ((String)(pathList.get(pathList.size()-1)));
    return ladder;
    private EdgeNode findSmallest(LinkedList distance, LinkedList visited) {
    EdgeNode min = new EdgeNode("****",999);
    for(int i=0;i<distance.size();++i) {
    String node = (String)(((EdgeNode)distance.get(i)).getVertex());
    if(!visited.contains(node)) {
    if(((EdgeNode)distance.get(i)).getCost()<min.getCost()) {
    min = (EdgeNode)distance.get(i);
    return min;
    // class that represents nodes inserted into path set
    private class PathNode {
    protected String sv;
    protected String ev;
    public PathNode(String s,String e) {
    sv = s;
    ev = e;
    public String getEnd() {
    return ev;
    public String getStart() {
    return sv;
    public void setEnd(String n) {
    ev = n;
    public boolean equals(Object o) {
    return this.sv.equals(((PathNode)o).sv);
    public String toString() {
    return "("+sv+":"+ev+")";
    }thank you

  • Need Help with Formula using SQL maybe

    I need help!  I work with Crystal reports XI and usually manage just fine with the Formula editor but his one I think will require some SQL and I am not good at that.
    We are running SQL 2000 I think (Enterprise Manager 8.0)  Our sales people schedule activities and enter notes for customer accounts.  Each is stored in a separate table.  I need to find activities that are scheduled 240 days into the future and show the most recent note that goes with the account for which that activity is scheduled.
    The two tables, Activities and History, share the an accountID field in common that links them to the correct customer account.   I want to look at dates in the Startdate.Activities field more than 240 days in the future and show the most recent note from the History table where the accountid's match. I figure my query will contain a join on AccountID.Activities and AccountID.History used with Max(completedate.History) but I do not understand how to word it.
    I would like to perform all this in crystal if possible.  I humbly request your help.
    Membery

    You SQL would look something like this...
    SELECT
    a.AccountID,
    a.BlahBlahBlah, -- Any other fields you want from the Activities table
    h.LastComment
    FROM Activities AS a
    LEFT OUTER JOIN History AS h ON a.AccountID = h.AccountID
    WHERE (a.ActivityDate BETWEEN GetDate() AND DateAdd(dd, 240, GetDate()))
    AND h.HistoryID IN (
         SELECT MAX(HistoryID)
         FROM History
         GROUP BY AccountID)
    This method assumes that the History table has a HistoryID that increments up automatically each time a new comment is added... So a comment made today would always have a higher HistoryID that one made yesterday.
    If I'm wrong and there is no HistoryID or the HistoryID doesn't increment in a chronological fashion, it can still be done but the code is a bit more complex.
    HTH,
    Jason

  • Really need help (motor control using labview)

    hi all readers,
    im new beginner. really need help for my project. i've been assigned to monitor/control motor using labview 8.5 (using NI DAQmx). the problem is, the techinician told me that i cant use 3phase motor with this card. things that i need to displayed using labview is :
    torque
    power
    current
    voltage
    speed
    really appreciated if readers can help me with this:
    wut type of motor shud i use that compatible with NI DAQmx
    thanks a lot.

    Hi fauziana,
    NI data acquisition devices are primarily designed to take measurements, so it's a good idea to measure the signals that you have mentioned with a DAQ device.
    You also can use DAQ devices for control tasks, but for reliable and deterministic control behavioryou typically need to use a real-time operating system (not Windows!). If you want to learn more about the pros and cons of using DAQ devices for motion control tasks, please refer to these threads. Still for standard motion control tasks it's much more efficient in terms of development time, to use a dedicated motion control device for the motion control part of your application.
    In general the control part is independant from the motor type, as these devices only generate control signals (+/- 10 V). There are many power drives available, that accept this type of control signal and you should select your motor according to the requirements of your application.
    For a more detailed system consulting, please contact your local NI branch. To select the products that fit best to your application requirements a face to face discussion is much more efficient than a discussion forum thread, because there are a lot of parameters that need to be taken into consideration. If you tell me in which country you are living, I can provide appropriate contact data to you.
    Thanks and kind regards,
    Jochen Klier
    National Instruments

Maybe you are looking for