Board index » jbuilder » How to Insert a row and how not to...

How to Insert a row and how not to...


2003-11-27 10:23:01 AM
jbuilder24
this works: [mySQL,
jdbc]
try {
persons.insertRow(false);
persons.setString("Name","Abe665");
persons.setString("FirstName","freddy665");
int ie = 955;
persons.setInt("EmployeeNumber",ie);
BigDecimal bigd = new BigDecimal("665.13");
persons.setBigDecimal("BaseRemuneration",bigd);
String sqd = "1985-11-25";
persons.setDate("BirthDate",java.sql.Date.valueOf(sqd));
persons.post();
persons.saveChanges();
}
catch (DataSetException dse) {
System.out.print ( " dse " + dse );
}
BUT my first attempt had a loop on columns with post and saveChanges
done for each column - This did not work, after the first post
(and|or?) saveChanges the record "flies away" as the help so
charmingly says, and you cant edit any more fields.
So what is post and SaveChanges... do I need both??
I'm not sure what happens if you try insertRow(true) ???
cheers
Kelvin
 
 

Re:How to Insert a row and how not to...

Trying to do a simple task with JB database,
I am suposed to write a "Resolver"
[I guess Borland expect me to hand chisel every stone in my house as well,
I mean what am I paying thse guys for (not)]
anyway as everyone knows "Automatic Knowledge" is the leading symptom
on any locked psychiatric ward
- Automatic knowledge, in case you dont know, is when the insane one
believes that everyone MUST know what is inside his head.
So Borland assume I MUST know how to (and want to )write a "Resolver"
so I finds a piece of code:
public void resolveData(DataSet dataSet) {
StorageDataSet sds = dataSet.getStorageDataSet();
ProviderHelp.startResolution(sds, true);
// Inserts
DataSetView iv = new DataSetView();
int ic = sds.getInsertedRowCount();
if (ic>0) {
sds.getInsertedRows(iv);
ResolveInserts(iv); // what do we do in here??
} // Inserts
// Updates
DataSetView uv = new DataSetView();
int uc = sds.getUpdatedRowCount();
if (uc>0) {
System.out.println("resolv AAB updated rows " + uc ); //ttt
sds.getUpdatedRows(uv);
ResolveUpdates(uv);
} // Updates
etc etc
Notice how we are in an infinite regress here... I have found how to
"ResolveData, just as long as I know how to ResolveUpdates()
[ sob...]
btw if you try database.getDatabase1().saveChanges(tables)
which might be any retired psychiatric nurse's attempt at "ResolveUpdates"
the machine tells you
"DataSet changes are currently being saved. Retry operation later"
Nurse, fetch the straightJacket.......
 

Re:How to Insert a row and how not to...

********************************************
Nurse Ratchet showed me this code from Borland FAQ151
I was about to admit my fault
and flagellate myself with barbed wire rosary beads,
until I ran the code
and blow me down
it does NOT work
dat old null pointer
[A clue... the capital I in If shows this code
has NEVER been tested on ANY MACHINE.
Do I detect the dead hand of a computer science graduate?
I bet his professor gave him top marks for this chalice of rancid...]
NON FUNCTIONING CODE FROM THE FAQ...
********************************************
At initialization time, set up the following:
DataRow originalRow = new DataRow(dataSet);
DataSetView updatedView = new DataSetView();
dataSet.getUpdatedRows(updatedView);
Variant value1 = new Variant();
Variant value2 = new Variant();
Then, when you need to see if a column value is changed, do this:
If ((dataSet.getStatus() & RowStatus.UPDATED) != 0) {
updatedView.goToInternalRow(dataSet.getInternalRow());
dataSet.getOriginalRow(updatedView, originalRow); // ALAS &
ALACKADAY nullpointer
originalRow.getVariant(ordinal, value1);
dataSet.getVariant(ordinal, value2);
return !value1.equals(value2);
}
return false;
******************************************************
dontcha just love all that fancy graduate school "View" stuff? [not]
Pity its not chiseled on a brick, then at least we could use it as a
doorstop.
Anyway DataSet does not do getUpdatedRows it hasta be a StorageDataSet
[Hey. I didnt start this pedantry]
and StorageDataSet getOriginalRow does NOT take DataSetView as a
paramater.
Can all the computer Science types at Borland go to at least one
meeting with at least
one programmer, and get some wheels on this thing????
********************************************************
 

{smallsort}

Re:How to Insert a row and how not to...

Well, I finally faced up to it:
QueryResolver is what I needed
It is simpler than it sounds,
dont bother with getOriginalRow
- although it can be made to work...
using the post by Michael Rachow 2001-06-20 06:11:27 PST
PLUS the extra line
Try this
DataRow originalRow = new DataRow(persons); // extra ya hafta do this
// queryDataSet1 changed or not
queryDataSet1.post();
if(queryDataSet1.changesPending())
queryDataSet1.getOriginalRow(queryDataSet1,originalRow);
else
// The columns of originalRow should have empty values.
nb getoriginalRow still throws exception after a delete, so a try/catch
must be added to the above.
But for my needs, goodbye to all that,
QueryResolver rules OK
now pass me the seven joyful mysteries made of razor wire
so I can commence my penance...
Ckeers kelvinq
 

Re:How to Insert a row and how not to...

re last post
Quote
new DataRow(persons); // extra ya hafta do this
obviously I meant
new DataRow(queryDataSet1); // extra ya hafta do this
..for me persons is a QueryDataSet
(as another poster said,,,"why did Borland make them so horrible?")
(actually its a table, but when in Borland, I try to talk like a
Borlander)
Now for best, most irritating and most timewasting Borland problem
today:
"com.borland.dx.dataset.DataSetException: Attempt to set a TIMESTAMP
value to a TIMESTAMP value."
can anyone beat that for a fatuous, absurd & keyboard-rage provoking
red-line error message???
Maybe Borland {*word*88}s on mySQL Timestamps, I will try to revert to
DateTime
(I curse the day I thought it might be nifty to change from DateTime
to Timestamp)
cheers
KelvinQ
 

Re:How to Insert a row and how not to...

re TIMESTAMP in MySQL...
depending on MAXDB (No relation to Max Headroom?)
TIMESTAMP may be automaticaly setting its tiny self
so it makes a kind of sense that ya cant set TIMESTAMP = TIMESTAMP
(in fact ya cant even set the 1st 1 to now...)
SO its back to DateTime
UNLESS I can get reassurance that Borland, MAXDB and MySQL can all
hold hands in an amicable manner.
by now youre all saying "why didnt he check
www.mysql.com/doc/en/DATETIME.html
when he sat down this morning?"
you might well ask...
cheers
kelvinq
 

Re:How to Insert a row and how not to...

so I removed ALL TIMESTAMPS from the database (using SQLyog which has
one millionth of the bugs that JBuilder has!)
and I removed ALL TIMESTAMPS from the code,
but now I get
com.borland.dx.dataset.VariantException: Attempt to set a DATE value
to a TIMESTAMP value.
THis CANNOT be happening, there are NO TIMESTAMPS within 5 miles of
here.
So this is the 3rd day I have spent fighting JBuilder to set some
dates.
Java and JBuilder cannot last, within a few years there will be
something else,
All this CompSci perfection is Unuseable...
cheers
kelvinQ
 

Re:How to Insert a row and how not to...

So I take a vote: has the modify table structure in SQLyog worked??
SQLyog says it has ie both persons & history tables are now datetime NOT timestamp
======================================================================
mysql says this:
mysql>show columns from persons;
+-------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+---------------+------+-----+---------+----------------+
.....
| ModifyDate | datetime | YES | | NULL | |
mysql>show columns from history;
+-------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+---------------+------+-----+---------+-------+
| ModifyDate | datetime | YES | MUL | NULL | |
======================================================================
SO BOTH tables are now datetime
and mySQL is the TRUE test - there is NO TIMESTAMP anywhere...
BUT JBuilder is still stuck with this morning's structure:
persons col name ModifyDate type 15
history col name ModifyDate type 13
it STILL has history ModifyDate as a type 13 = TIMESTAMP
- this is after a reboot.
How long must we wait for JBuilder to catch up with reality???
What weird memory is persisting in using an obsolete database structure??
 

Re:How to Insert a row and how not to...

So I thought I might use Datatime (which ADO is perfectly happy with
in Access & mySQL)
But JBuilder/jdbc seems to {*word*88} on the very thought:
Trying either
history.setDate("ModifyDate",java.sql.Date.valueOf("2001-08-07"));
// dse
history.setDate("ModifyDate",System.currentTimeMillis ());
// dse
gives this stupid looking error message:
errorcom.borland.dx.dataset.DataSetException: The row specified by
the resolution query was not found.
Typical reasons are:
Somebody deleted or changed this row.
A floating point comparison failed to match.
A CHAR field needs space padding (see
Database.setUseSpacePadding).
Now I dont mind fatuous chatty error messages iff they are helpful,
but here
it would be better to see a message like
"Borland regrets we have totally failed to get a grip on sql datetime,
youre on your own..."
 

Re:How to Insert a row and how not to...

So I hoped to get around Borlands limitations by using sql commands
but not only does JBuilder fight me at every step
but it will not accept sql statements.
so I cannot recommend JBuilder/jdbc
simple sql statements like
"UPDATE history SET FirstName = 'Mary' WHERE Name = 'Bald'; ";
are NOT allowed by JBuilder...
all I am allowed to say is
"select * from history"
then any JBuilder limitations are enforced upon me...
my advice...
get another database language
 

Re:How to Insert a row and how not to...

So now mySQL timestamps are modifying themselves when I change a
record
but I cant read them ie read-only fields that cant be read!!!
except by some other non Borland software!
I wish I could tell our clients to get SQLyog
but that would kind of close our business...
Actually I can reasd the timestamp,
I have to make something called a Column
and give JBuilder a list of "Columns"
this is after I have opened the table and JBuilder has
got hold of the metadata, that is of NO USE
I must definethem all over again.
Oddly, this variable, which I called cmodifydate
is defined simply by:
Column cmodifydate;
cmodifydate.setColumnName("ModifyDate");
cmodifydate.setDisplayMask("dd/MM/yyyy");
so JBuilder determines its type from the metadate!!!
but I must say
persons.setColumns(new Column[] {blah,blah... cmodifydate});
why is this redundant code needed??
I already have a variable called modifydate a JDBTextfield
setup thus:
modifydate.setColumnName("ModifyDate"); //md3
modifydate.setDataSet(dma.getPersons()); //md4
this displays the modifydate TimeStamp nicely
Isnt it bizarre that I must define the format of the jdbTextfield by
informing cmodifydate, which is a "Column" and nothing to do with the
textfield, or so it would seem to the meanest intelligence.
So I cant write to a timestamp, I cant read a timestamp, but i CAN
show it on the screen in a jdbtextfield, after I have made a
completely independent "Column" field, and sent the format to the
column field!!!
I guess If I really want to read a timestamp, I need to make an
onscreen jdbTextfield, a "sibling" Column which is magically linked,
and then make the field invisible!!!
Stranger things have happened in wartime, but not much!!!!
 

Re:How to Insert a row and how not to...

trying to deploy.......
now the last jar error I can see is:
The driver: com.mysql.jdbc.Driver could not be loaded.
This could be a problem with the driver itself, or that the driver
is not found on the classpath.
and we have:
CLASSPATH=C:\JBuilder9\lib\ext\xlrd.jar;C:\JBuilder9\lib\ext\mysql-connector-java-3.0.8-stable-bin.jar;C:\j2sdk1.4.1_02\lib;
so whats up with that?????
how can I set the classpath more solidly??
Maybe If I pour a couple of yards of ready-mix concrete over the
computer it will be solid enough???
The JBuilder deploy wizard is a dunce...
So I added all these to My.jar
\JBuilder9\lib\mysql-connector-java-3.0.8-stable-bin.jar
\SkinLF\skinlf-1.2.4\lib\skinlf.jar
\SkinLF\skinlf-1.2.4\lib\aquathemepack.zip
\SkinLF\skinlf-1.2.4\lib\nativeskin.jar
\JBuilder9\lib\dx.jar; [this baby doesnt seem to exist]
\JBuilder9\lib\beandt.jar
\JBuilder9\lib\dbswing.jar
\JBuilder9\lib\jbcl.jar
Still get this error (amongst heaps of others...)
at t21.Application1.main(Application1.java:68)
Frame1 init exceptioncom.borland.dx.dataset.DataSetException: The
driver: com.mysql.jdbc.Driver could not be loaded. This could be a
problem with the driver it
self, or that the driver is not found on the classpath.
See com.borland.dx.dataset.DataSetException error code: BASE+83
com.borland.dx.dataset.DataSetException: The driver:
com.mysql.jdbc.Driver could
not be loaded. This could be a problem with the driver itself, or
that the driver is not found on the classpath.
at com.borland.dx.dataset.DataSetException.a(Unknown Source)
at com.borland.dx.dataset.DataSetException.driverNotLoadedAtRuntime(Unknown
Source)
at com.borland.dx.sql.dataset.Database.addDriver(Unknown
Source)
So Java a la Borland is a Non-Deployable Bunny,
Pass me that Energiser Microsoft bunny please...
===============================
 

Re:How to Insert a row and how not to...

just a comment on this old comment from pnichols (paul@computer-logic)
Subject: Re: Can't run in other computer
use the jar Builder and deploy all of the dependency files in your
jar. This will make deployment a breeze.
I put all the jars in my.jar...
well I cant even run my application on the same computer, outside the
IDE
so the "breeze" which I am offered smells rather bad from here...