» »

[Java] Shranjevanje podatkov in datotek

[Java] Shranjevanje podatkov in datotek

bijonda ::

Hallo!

EN problem resen, zdaj pa drugim! Imam napisan program, ki mi vrne podatke nekatrih dokumentov. Zdaj moram te podatke shraniti v polja oz na neko listo. Jaz jih mislim shraniti v neko datoteko ki bi bila kar na mojem racunalniku. Do daokumentov pa dostopam prek mreze, kar pomani da niso na mojem racunalniku.
Se mogoce se komu sanja zakaj mi noce delati program v netbeansu:

public class Document {
    /** Creates a new instance of Document */
    public Document() {
         String koda;
         String izdaja;
         String opis_dokumanta;
    }
        //konstruktor
        public Document (String k, String i, String od){
            //tu mi javlja napako,  kao da mu koda ni vsec in 
            //tako je se pri ostali, izdaja in opis dokumanta, pa vse do
            this.koda = k;                    
           //dol,   kjer se pojavljajo te besede
            this.izdaja = i;
            this.opis_dokumanta = od;
        }
        
        public Document(String s) {
           String[] t = s.split(":");
           this.koda = bindv.record_name4(0);
           this.izdaja = bindv.record_recalt(0);
           this.opis_izdaje = bindv.record_desc(0);
        }
        
        //metoda
       public String toString() {
           return koda + " " + izdaja + " " + opis_dokumanta;
       }
}


Hvala za odgovore!

Lep dan vam zelim!

Ciao ciao Bijonda
  • spremenil: kopernik ()

kopernik ::

Poskusi takole:
public class Document {
  String koda;
  String izdaja;
  String opis_dokumanta;

  /** Creates a new instance of Document */
  public Document() {
  }

  // konstruktor
  public Document(String k, String i, String od)
  {
    this.koda = k;
    this.izdaja = i;
    this.opis_dokumanta = od;
  }

  public Document(String s) {
    String[] t = s.split(":");
    this.koda = bindv.record_name4(0);
    this.izdaja = bindv.record_recalt(0);
    this.opis_izdaje = bindv.record_desc(0);
  }

  // metoda
  public String toString() {
    return koda + " " + izdaja + " " + opis_dokumanta;
  }
}

Zgodovina sprememb…

  • spremenil: kopernik ()

kopernik ::

Kje pa imaš definirano spremenljivko bindv ?

bijonda ::

To imam dafiniran ze v drugem razredu in mi dela brez problemov. Lahko ti se tega poslem. Samo mi te spremenljivke ne motijo in jih netbeans "zazna" brez problemov!
Haval! BNom probala tvoj program!

bijonda ::

Sem ze sama to prej probala, pa tudi ne dela! ;) Sej se je mlad dan in bomo nasli kako resitev!

kopernik ::

Meni v Eclipse-u dela. Tudi v netbeans bi moralo. Kakšno napako ti javi, ko napišeš razred tako, kot sem ti predlagal ?

bijonda ::

Evo problema. Program je napisan in vse dela kakor treba. le da ne vem kako bi zdaj te podatke shranila v" datoteko" in da bi lahko te zapise pogledala v datoteki".
Tuki je program:
/*
 * List some record and ref information for some parts.
 */

import HLIWrapper.*;
import java.io.*;

/**
 * Sample program to connect to Sherpa DMS and list parts and it’s children.
 * This program will work on a PIMDEMO database, i.e. a database created
 * through the Sherpa/PIMS setup scripts. Or any other database specified in
 * environ.ini in current directory if DbName is set to "DEFAULT" or "" in
 * the program. The DbName specified in this program
 * will supersede the ones defined the environ.ini.
 */

public class DMS implements DMSMsgCodes {
    
    String polje;
    public void MyDocs()  {
        Db db = null;
        
        // This is needed later for the fetching data from Sherpa/DMS
        BindV bindv = null;
        String koda;
        String izdaja;
        String opis_dokumanta;
        
        // Create a new Hli object. During the instantiation of the
        // Hli object the shared object which contain the native methods
        // to gets loaded in the memory.
        Hli hli = new Hli();
        
        // Set all the database and user information
        String DbName = new String("pro_base");
        String UserName = new String("wilson");
        String HostName = new String("ntdms");
        String PCSrvrName = new String("sherpasv");
        String Password = new String("welcome");
        
        try {
            // Get an Sherpa/DMS database object from the Hli.
            // The arguments passed are used differently depending on the
            // installation type and platform.
            // The PCSrvrName is used only for PC Client.
            // If the DbName is "DEFAULT" or ""  for PC Client and NT Client then
            // the DbName is taken from environ.ini.
            // By default dms_listoff() and dms_msgoff() are done in this routine.
            db = hli.ConnectDb(HostName,PCSrvrName,DbName, UserName, Password);
            
            // This is the equivalent of dms_bind_all
            db.Bind("group1");
            
            db.dms_execute("LIST RECORD DOCUMENT\\*\\*  /WHERE=\" owner = \"\"zfur\"\" and reclevel=\"\"CREATED\"\"\" name4,recalt,desc");
            for (;;) {
                // Get the next set of results.
                bindv = db.dms_fetch("group1");
                if (db.dms_msgcode() == DMS_EOF) // End of results
                    break;
                if (db.dms_msgcode() != DMS_OK) // Error
                {
                    System.out.println(db.dms_msgtext());
                    continue;
                }
                // Print the part record specification
                
                System.out.println("Koda: " + bindv.record_name4(0));
                System.out.println("Izdaja dokumanta: " + bindv.record_recalt(0));
                System.out.println("Opis dokumanta: " + bindv.record_desc(0));
                
                koda = bindv.record_name4(0);
                izdaja = bindv.record_recalt(0);
                opis_dokumanta = bindv.record_desc(0);
                
                polje = koda + " " + izdaja + " " + opis_dokumanta;
            }
        }
        
        catch (DMSException e) {
            /* if one of the dms commands fails, print the error */
            System.out.println(e);
            if(db.dms_msgcode() == DMS_NOSUCHDB)
                System.out.println("Please modify the DbName in this program and try this again.");
            
        }
        
    }
    
    public void zapisi(String ime, String polje) throws IOException{
        PrintWriter dat = new PrintWriter(new FileWriter("Datoteka"));
        dat.println(polje);
        
        dat.close();
    }
    
    public static void main(String[] args){
        DMS l = new DMS();
        
        l.MyDocs();
        
        // Do the following for PC Client programs.
        // This will free the Hli Connection, if not there will be an
        // error message display on the screen.
        HLIWrapperUtils.cleanup();
    }
}

Uporabljam pa netbeans. Izpise mi :
Izdaja dokumanta: 010
Opis dokumanta: Sopran - zahteva za verifikacijo in poro?ilo verifikacije
Koda: SOP100700-ASL-
Izdaja dokumanta: 030
Opis dokumanta: Produkt, projekt, konfiguracija produkta v Sopranu
Koda:
Izdaja dokumanta: 010
Opis dokumanta: Tvorjenje diff in pdf datotek dokumentov izdanih v Sopranu
Koda:
Izdaja dokumanta: 010
Opis dokumanta: Predlog optimizacije izdelave paketov

Kar bi tudi moralo.Zdaj bi rada te podatke shranila v mapo Dokumant!
Prosim pomagaj te mi!

Haval za vaso pomoc!
Lep dan vam zelim!

Ciao ciao Bijonda

Zgodovina sprememb…

  • spremenil: Vesoljc ()

Vesoljc ::

@bijonda

v tej temi je na dnu ena slikica, kako oznaciti kodo, da jo forum potem pravilno pokaze (le namesto keyworda c uporabi java).
Abnormal behavior of abnormal brain makes me normal...


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[JAVA] HTTPS client

Oddelek: Programiranje
173057 (1787) peterv6i
»

Quick sort ascending/descending

Oddelek: Programiranje
161900 (1580) infiniteLoop
»

[JAVA] branje iz datoteke

Oddelek: Programiranje
242281 (1916) Bela01
»

[JAVA] zaustavitev niti (threadov)

Oddelek: Programiranje
223048 (3048) morbo
»

[Naloga][Java] Ulomki

Oddelek: Programiranje
62541 (2389) SkIDiver

Več podobnih tem