aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Data: Unexpected database access problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Data: Unexpected database access problem" Watch "Data: Unexpected database access problem" New topic
Author

Data: Unexpected database access problem

ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
I have developed a standalong application using JTable to show the initial flight information.
I am getting this Data: Unexpected database access problem when I run the application.
The code is as follows :
String os = ( String ) System.getProperty("os.name");
// if it is windows system
if ( os.startsWith("W") ) {
dbPath = "\\assignment\\scjd\\starting\\classes\\suncertify\\db\\db.db";
} // else if it is unix system
else {
dbPath = "/assignment/scjd/starting/classes/suncertify/db/db.db";
}
db = new Data(dbPath);
} catch(java.io.IOException io)
{}
String[] columnNames = { "Flight #" , "Origin Airport" , "Destination Airport" , "Carrier #" , "Price" , "Day" , "Time" , "Duration" , "Available Seats" };
int count = db.getRecordCount();
rowData = new String[count][9];
DataInfo row = null;

for ( int i = 1; i < count; i++ ) {
try {
if ( null != ( row = db.getRecord(i) ) ) {
rowData[i] = row.getValues();
}
} catch(DatabaseException dbe)
{
System.out.println(dbe.getMessage());
}
}
Data: Unexpected database access problem
Data: Unexpected database access problem
Data: Unexpected database access problem
Data: Unexpected database access problem
Data: Unexpected database access problem
Data: Unexpected database access problem ......

Any solutions ?
Thanks in advance.
-- Ravindra


SCJP, SCJD, SCWCD, SCBCD, SCEA
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Your getRecord is returning this error for an IOException.
It getRecord calls the readRecord method. Did you fix the deprecated method there?
I'd look there. And my spider senses are saying to me that there is an easier way to get the file path, and file without having to find out what Operating system they are using. And it says it might be easier if the db.db file resided in the same directory as where you start your app.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Hi Mark
I am getting this data access error after I tried to fix the deprecated method as given below.
//rv[i] = new String(buffer, 0, offset, description[i].getLength());
String enc = "ISO-8859-1";
rv[i] = new String(buffer, 0, offset, enc);
//newData[i].getBytes(0, toCopy, buffer, offset);
String enc = "ISO-8859-1";
newData[i].getBytes( enc );
Let me know the correct way if this is wrong.
And my spider senses are saying to me that there is an easier way to get the file path, and file without having to find out what Operating system they are using. And it says it might be easier if the db.db file resided in the same directory as where you start your app
I am testing the FBN in standalone mode. I have three folders client , data and server. I am runing FBNClient in client folder and db.db is located in data . Does this mean that db.db should be located in client folder for standalone mode ?
Thanks
-- Ravindra
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

//rv[i] = new String(buffer, 0, offset, description[i].getLength());
String enc = "ISO-8859-1";
rv[i] = new String(buffer, 0, offset, enc);

Which String constructor is this? I can't find it in my API documentation. It looks like the same one that they had in there originally which is deprecated.
Did you compile it with the -deprecated argument in javac?
Look again
Mark
ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
I am referring to JDK 1.2 API . This is what it says...
public String(byte[] ascii,int hibyte,int offset,int count)
Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a character-encoding name or that use the platform's default encoding.
String
public String(byte[] bytes,int offset,int length,String enc) throws UnsupportedEncodingException
Construct a new String by converting the specified subarray of bytes using the specified character encoding. The length of the new String is a function of the encoding, and hence may not be equal to the length of the subarray.

-- Ravindra
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

That's fine to use that constructor. There is still something in your coding of it that is throwing me off somewhere.
rv[i] = new String(buffer, 0, offset, enc);

and
public String(byte[] bytes,int offset,int length,String enc)

OK, the byte array as the first parameter is correct.
the second parameter is the offset, which you have as the third parameter. The offset is assigned 1, and you are passing 0 as the second parameter. Let alone it is a Magic Number.
So then for length you have the offset variable being passed. The values to the constructor you are passing are wrong.
try



Mark
ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Hi Mark
It has worked after I made the following change in the code.
String enc = "ISO-8859-1";
rv[i] = new String(buffer, offset, description[i].getLength(), enc);
Thanks
Ravindra
Najib Coutya
Greenhorn

Joined: Dec 18, 2001
Posts: 28
Do we really need the encoding at the end?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Originally posted by Najib Coutya:
Do we really need the encoding at the end?


Nah not really. I didn't.
Mark
ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Is it wrong if I use it ?
Thanks
Ravindra
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Nope it's neither right or wrong if you use it or not. The only time you really have to use it is when you application is going to be multi-national. Meaning it will run in China, Japan, Russia, France, Italy, Spain, and USA.
I think
Mark
Najib Coutya
Greenhorn

Joined: Dec 18, 2001
Posts: 28
Mark,
Thanks for your reply.
Even when the FlyByNight is going to be multi-national, encoding alone is not going to solve it. We probably need to change the readUTF and writeUTF as well as selecting an encoding from the environment. Because my understanding is that they force UTF encoding.
Is that a right assumption?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data: Unexpected database access problem
 
Similar Threads
strange behaviour of Class Data
DataInfo getValues() problem- see code
package structure and location of db.db file
Help on Displaying Query Result in JTable
Thoughts wanted READMDE.txt