Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] database question

Started by role Apr 25, 2003 at 2:39 AM 1 replies 600+ views
Original Post
role
role
hello, i want to make a very very big database maybe about 30,000 records is there any class can i use to make it? it''s just a simple database, i don''t think i would use jdbc, it''s overwhelming! the records only have 3-4 field and all field is simple String. and use for local computer only. i try to use simple write to file, but got very poor performance (loading and saving the records everytime) so any database that very simple to use? (only for saving and loading the records) thanx in advance
cwraith
cwraith
First off, 30,000 records is small. Well, unless your average record is 10k or something huge like that.

Second, if you want the full flexibility of a database, JDBC actually is quite easy.. And if you use it with something like Hypersonic SQL DB, you don''t even need to worry about setting up and securing an external database.

If you don''t need everything a database offers, check to see if some combination of the collections libraries (Lists, Sets, Maps, etc) help.

As far as IO speed... Using a decent IO system, 30,000 records shouldn''t take very long to read or write. As long as you don''t read or write the full structure on every change, there shouldn''t be a problem.

If you post the code you''re using, as well as the operations you need to be able to perform, I can probably help quite a bit more.
role
role
huh?? 30,000 records is small?? really??
i want to use JDBC, but i read the tutorial and i got confuse...
it said i must install JDBC, driver, and DBMS.
i have bad experience using database!
(can''t use database i made on another computer, must install drivers, very inconvenient!)
and i try to run the JDBC sample, but it use internet connection! i only want to use my database

on local computer, and the source code is very very lack of information.
i usually learn by example, reading all the article makes me sick.

the really problem of using decent IO System is not at the speed actually.
the problem is the memory it takes. i load 50,000 records and got OutofMemory Error!
cos i put all loaded String into a Hashtable (takes 80megs memory after that error)

if using database like paradox or umm oracle maybe... i don''t have to load all the object into memory isn''t it?
adding,removing,and finding records using database SQL is more simple than using Hashtable method i presume. (and doesn''t use extraordinary memory for sure)

so is there class that can make an ArrayList from a file? (without using large memory).
or can u point me to the basic of using JDBC (just for saving, loading, adding, removing, and finding records)
what i want to do is loading all object from a file then put it into a Vector.

okay this is the loader class i use (LoadTest.java) :

import java.io.*;
import java.util.*;

public class LoadTest {
private static Hashtable dbase = new Hashtable();

public static void main(String[] args) {
// load SampleFile.in
load(new File("SampleFile.in"));
}

private static void load(File inputFile) {
try {
FileReader in = new FileReader(inputFile);
BufferedReader readIn = new BufferedReader(in);
// the first line is the total line in that file
int dataLength = Integer.parseInt(readIn.readLine());
int i=0;
while (i < dataLength) {
// name of the object
String header = readIn.readLine();
i++; // must increment the line everytime we use readIn.readLine()
// read object''s content
String content = readIn.readLine(); i++;
StringBuffer attribute = new StringBuffer();
boolean finish = false;
while (!finish) {
content = readIn.readLine(); i++;
if (content.equals("===================="))
finish = true; else
attribute.append(content).append("\n");
}
dbase.put(header, attribute.toString());
}
readIn.close();

// testing database
Enumeration e = dbase.keys(); // dbase header
Enumeration attrib = dbase.elements();
while (e.hasMoreElements()) {
System.out.println(e.nextElement());
System.out.println(attrib.nextElement());
}
System.out.println("total line = "+i);
} catch (IOException e) { e.printStackTrace(); }
}
}


and input file (SampleFile.in) :

21
Jack
----------
AC = 14
STR = 10
AGL = 8
INT = 4
====================
Marry
----------
AC = 8
STR = 7
AGL = 12
INT = 8
====================
Ken
----------
AC = 20
STR = 25
AGL = 20
INT = 16
====================



thank you very much....

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.