Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to Create the Database - please help

 
Seshan Parameswaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have registered for the Developer Examination. The assignment given to me is the flight reservation system. I wrote the code to create the binary database file from the ascii file. It used to work before. All of a sudden, it stopped working. I traced the problem and found out that the error occurs in the invariant() function provided by Sun where it tries to check for the validity of the database.
The portion of the code that does this is
if (db.length() == headerLen + (recordLen * recordCount))
and the code fails at this point.
The error I get is
Exception in thread "main" java.lang.RuntimeException: Data: Internal error
at suncertify.db.Data.invariant(Data.java:499)
at suncertify.db.Data.add(Data.java:201)
at suncertify.db.CreateDatabase.<init>(CreateDatabase.java:33)
at suncertify.db.CreateDatabase.main(CreateDatabase.java:58)
This is the copy of the CreateDatabase function I wrote
________________________________________________________________
package suncertify.db;
import suncertify.db.*;
import java.io.*;
import java.util.*;
import java.awt.*;
public class CreateDatabase
{
private FieldInfo[] fldInfo;
public CreateDatabase()
{
try{
defineFields();
//System.out.println("After defineFields)");
String values[] = new String[9],text;
//System.out.println("Calling Data Constructor");
Data d = new Data("dbAir",fldInfo);
RandomAccessFile r = new RandomAccessFile("AirLine.txt","r");
while( (text = r.readLine () ) != null){
int ctr = 0;
StringTokenizer tokens = new StringTokenizer(text,"^",false);
while(tokens.hasMoreTokens ()){
//System.out.println("Has More tokens :" + tokens.hasMoreTokens());
//System.out.println(tokens.nextToken ());
values[ctr] = tokens.nextToken ();
//System.out.println(values[ctr]);
ctr++;
}
//for(int i = 0;i<values.length;i++)>
// System.out.println("Value #" + i + values[i]);
d.add (values);
}
System.out.println("Done");
}
catch(FileNotFoundException fnfex)
{
fnfex.printStackTrace();
}
catch(DatabaseException dbex)
{
dbex.printStackTrace();
}
catch(IOException ioex)
{
ioex.printStackTrace();
}
}
public static void main(String[] args)
{
CreateDatabase c = new CreateDatabase();
}
private void defineFields()
{
System.out.println("In defineFields()");
fldInfo = new FieldInfo[9];
fldInfo[0] = new FieldInfo("FlightNo",5);
fldInfo[1] = new FieldInfo("Origin",3);
fldInfo[2] = new FieldInfo("Destination",3);
fldInfo[3] = new FieldInfo("Carrier",12);
fldInfo[4] = new FieldInfo("Price",4);
fldInfo[5] = new FieldInfo("Day",3);
fldInfo[6] = new FieldInfo("Time",5);
fldInfo[7] = new FieldInfo("Duration",6);
fldInfo[8] = new FieldInfo("SeatsAvailable",3);
System.out.println("Exiting defineFields()");
}
}

________________________________________________________________
Could you please throw some light upon this?
Thanks
Seshan
 
Sindhu Sankaran
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove the package declaration .. and it should work fine ..
If you want your database load program to be in the same
package then remove the import statement.
 
Seshan Parameswaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sindhu,
Thank you for your reply.
Seshan
 
Liu Zhensheng
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,Seshan
I think this situation maybe one reason for the error:
When the data supplied in the flat text file does not meet the requirement of the database Metadata defination, for example, you supply 8 fields in the flat text file, but the
database has 9 fields, then when the add() call the writeRecord(), it will throw out an Exception and fail to add the the record into the database.
But NOTE the member variable recordCount of the Data instance increases ONE before the Exception and when you call add() method to insert next record into the database(what happens in your code), the add() method first calls invariant() to check whether the database is OK, then you will get the error infomation you POSTED here.
Hope this will give you some help.
LZS


[This message has been edited by Liu Zhensheng (edited December 04, 2000).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic