Design Advice Request - Using JDBC in a utility class
I have a utility class that I would like to use from any client code, regardless of whether that code is executing in a transaction or not.
This seems to greatly complicate the JDBC access from within the utility class. I appreciate any advice.
The utility class may both read from and write to the database. It currently attempts to detect whether it is in a transaction (it tests whether TransactionHelper.getTransactionHelper().getTransaction() is null to do this -- please point out if there is a better way.)
If in a transaction, the utility uses a data source which is linked to an XA connection pool, since it must assume other database activity may be occurring on the tx. If not in a transaction, however, it uses a data source linked to a non-XA connection pool, since the XA connection pool will not work outside of a transaction.
It seems like there should be an easier way -- are we overlooking some simpler solution?
The database is Oracle 9i and we are using the Oracle thin drivers.
Thanks in advance,
Ken Clark
Ken Clark wrote:
> I am not sure what you mean by this:
>
> "do all your JDBC work in the
> scope of a top-level method (or methods)
> with *all* jdbc variables method-level
> variables,"
I saw the code you sent me, and that is what it does, so no worries here.
>
> I originally built this with a non-XA DataSource, but found that when the utility was called from within a transaction, I would get errors that there was already a connection in use and that I therefore needed to use an XA connection.
>
> Switching to XA DataSource fixed that problem, but then in other cases when not in a transaction, I would get errors saying that an XA Connection could not be used outside a transaction.
>
> Since my utility has no control over the callers state, I came up with the solution stated previously, where I determine if in a Tx and then use the corresponding DataSource.
>
> Is there just a matter of configuration such that I can use a non-XA DS in all cases?
I am saying a non transactional DataSource, not a non XA data source. Ie, a datasource that
is unaware of whether there is a UserTransaction underway. A transactional data source can
be either XA or not. In the former case, multiple XA connections can and will be entrained
in any ongoing transactino, and non-XA (but transactional) datasources can and will be
used in a tx, but only one per tx because they have no 2-phase commit capability.
Ie; In the config file, you will see TxDataSource for a transactional datasource
to a pool (whether XA or not), and you will see DataSource for a non-transactional
data source.
Joe
Similar Messages
-
RE: [iPlanet-JATO] Re: Use Of models in utility classes
Hi all,
if you add the following to your spider2jato.xml
It will automatically map your CSpDataObject.executeImmediate to use
ExecuteImmediateUtil.executeImmediateSelect with the arguments mapped as
well.
Kostas
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpDataObject[.\s]*executeImmediate[\s]*\(([^,]*),([^)]*)\)]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpDataObject[.\s]*executeImmediate[\s]*\(([^,]*),([^)]*)\)]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[ExecuteImmediateUtil.executeImmediateSelect($1,$2,
getRequestContext())]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
-----Original Message-----
From: Matthew Stevens
Cc: vnamboori@y...
Sent: 11/29/01 11:23 AM
Subject: RE: [iPlanet-JATO] Re: Use Of models in utility classes
Namburi,
I have included an example in the file ExecuteImmediateUtil.java
The Yahoo Group will not handle the attached file we will put it in the
Files section shortly.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100253094145066046167121181">vnamboori@y...</a>]
Sent: Thursday, November 29, 2001 12:29 PM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes
Matt,
For CSpSelect.executeImmediate() I have an example of custom helpermethod as a replacement which uses JDBC results instead of
CSpDBResult.
Can you send me this example.
Thanks
Namburi
--- In iPlanet-JATO@y..., "Matthew Stevens" <matthew.stevens@E...>
wrote:
Namburi,
I will post a document to the group site this evening which has thedetails
on various tactics of migrating these type of utilities.Essentially, you
either need to convert these utilities to Models themselves or keepthe
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of custom helpermethod
as a replacement whicch uses JDBC results instead of CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes. These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do the
manipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion for these
utilities we have to do manually.
My question is Can we access the the models in the post migration
sameway or do we need requestContext?
We have lots of utility classes which are DataObject intensive.Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
For more information about JATO, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jsp
[Non-text portions of this message have been removed]
For more information about JATO, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jsp
[Non-text portions of this message have been removed]Hi all,
if you add the following to your spider2jato.xml
It will automatically map your CSpDataObject.executeImmediate to use
ExecuteImmediateUtil.executeImmediateSelect with the arguments mapped as
well.
Kostas
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpDataObject[.\s]*executeImmediate[\s]*\(([^,]*),([^)]*)\)]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpDataObject[.\s]*executeImmediate[\s]*\(([^,]*),([^)]*)\)]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[ExecuteImmediateUtil.executeImmediateSelect($1,$2,
getRequestContext())]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
-----Original Message-----
From: Matthew Stevens
Cc: vnamboori@y...
Sent: 11/29/01 11:23 AM
Subject: RE: [iPlanet-JATO] Re: Use Of models in utility classes
Namburi,
I have included an example in the file ExecuteImmediateUtil.java
The Yahoo Group will not handle the attached file we will put it in the
Files section shortly.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100253094145066046167121181">vnamboori@y...</a>]
Sent: Thursday, November 29, 2001 12:29 PM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes
Matt,
For CSpSelect.executeImmediate() I have an example of custom helpermethod as a replacement which uses JDBC results instead of
CSpDBResult.
Can you send me this example.
Thanks
Namburi
--- In iPlanet-JATO@y..., "Matthew Stevens" <matthew.stevens@E...>
wrote:
Namburi,
I will post a document to the group site this evening which has thedetails
on various tactics of migrating these type of utilities.Essentially, you
either need to convert these utilities to Models themselves or keepthe
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of custom helpermethod
as a replacement whicch uses JDBC results instead of CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes. These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do the
manipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion for these
utilities we have to do manually.
My question is Can we access the the models in the post migration
sameway or do we need requestContext?
We have lots of utility classes which are DataObject intensive.Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
For more information about JATO, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jsp
[Non-text portions of this message have been removed]
For more information about JATO, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jsp
[Non-text portions of this message have been removed] -
Namburi,
When you said you used the Reg Exp tool, did you use it only as
preconfigured by the iMT migrate application wizard?
Because the default configuration of the regular expression tool will only
target the files in your ND project directories. If you wish to target
classes outside of the normal directory scope, you have to either modify the
"Source Directory" property OR create another instance of the regular
expression tool. See the "Tool" menu in the iMT to create additional tool
instances which can each be configured to target different sets of files
using different sets of rules.
Usually, I utilize 3 different sets of rules files on a given migration:
spider2jato.xml
these are the generic conversion rules (but includes the optimized rules for
ViewBean and Model based code, i.e. these rules do not utilize the
RequestManager since it is not needed for code running inside the ViewBean
or Model classes)
I run these rules against all files.
See the file download section of this forum for periodic updates to these
rules.
nonProjectFileRules.xml
these include rules that add the necessary
RequestManager.getRequestContext(). etc prefixes to many of the common
calls.
I run these rules against user module and any other classes that do not are
not ModuleServlet, ContainerView, or Model classes.
appXRules.xml
these rules include application specific changes that I discover while
working on the project. A common thing here is changing import statements
(since the migration tool moves ND project code into different jato
packaging structure, you sometime need to adjust imports in non-project
classes that previously imported ND project specific packages)
So you see, you are not limited to one set of rules at all. Just be careful
to keep track of your backups (the regexp tool provides several options in
its Expert Properties related to back up strategies).
----- Original Message -----
From: <vnamboori@y...>
Sent: Wednesday, August 08, 2001 6:08 AM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes - Pease don't
forget about the regular expression potential
Thanks Matt, Mike, Todd
This is a great input for our migration. Though we used the existing
Regular Expression Mapping tool, we did not change this to meet our
own needs as mentioned by Mike.
We would certainly incorporate this to ease our migration.
Namburi
--- In iPlanet-JATO@y..., "Todd Fast" <toddwork@c...> wrote:
All--
Great response. By the way, the Regular Expression Tool uses thePerl5 RE
syntax as implemented by Apache OROMatcher. If you're doing lotsof these
sorts of migration changes manually, you should definitely buy theO'Reilly
book "Mastering Regular Expressions" and generate some rules toautomate the
conversion. Although they are definitely confusing at first,regular
expressions are fairly easy to understand with some documentation,and are
superbly effective at tackling this kind of migration task.
Todd
----- Original Message -----
From: "Mike Frisino" <Michael.Frisino@S...>
Sent: Tuesday, August 07, 2001 5:20 PM
Subject: Re: [iPlanet-JATO] Use Of models in utility classes -Pease don't
forget about the regular expression potential
Also, (and Matt's document may mention this)
Please bear in mind that this statement is not totally correct:
Since the migration tool does not do much of conversion for
these
utilities we have to do manually.Remember, the iMT is a SUITE of tools. There is the extractiontool, and
the translation tool, and the regular expression tool, and severalother
smaller tools (like the jar and compilation tools). It is correctto state
that the extraction and translation tools only significantlyconvert the
primary ND project objects (the pages, the data objects, and theproject
classes). The extraction and translation tools do minimumtranslation of the
User Module objects (i.e. they repackage the user module classes inthe new
jato module packages). It is correct that for all other utilityclasses
which are not formally part of the ND project, the extraction and
translation tools do not perform any migration.
However, the regular expression tool can "migrate" any arbitrary
file
(utility classes etc) to the degree that the regular expressionrules
correlate to the code present in the arbitrary file. So first andforemost,
if you have alot of spider code in your non-project classes youshould
consider using the regular expression tool and if warranted adding
additional rules to reduce the amount of manual adjustments thatneed to be
made. I can stress this enough. We can even help you write theregular
expression rules if you simply identify the code pattern you wish to
convert. Just because there is not already a regular expressionrule to
match your need does not mean it can't be written. We have notnearly
exhausted the possibilities.
For example if you say, we need to convert
CSpider.getDataObject("X");
To
RequestManager.getRequestContext().getModelManager().getModel(XModel.class);
Maybe we or somebody else in the list can help write that regularexpression if it has not already been written. For instance in thelast
updated spider2jato.xml file there is already aCSpider.getCommonPage("X")
rule:
<!--getPage to getViewBean-->
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getViewBean($1ViewBean.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
Following this example a getDataObject to getModel would look
like this:
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getModel($1Model.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
In fact, one migration developer already wrote that rule andsubmitted it
for inclusion in the basic set. I will post another upgrade to thebasic
regular expression rule set, look for a "file uploaded" posting.Also,
please consider contributing any additional generic rules that youhave
written for inclusion in the basic set.
Please not, that in some cases (Utility classes in particular)
the rule
application may be more effective as TWO sequention rules ratherthan one
monolithic rule. Again using the example above, it will convert
CSpider.getDataObject("Foo");
To
getModel(FooModel.class);
Now that is the most effective conversion for that code if that
code is in
a page or data object class file. But if that code is in a Utilityclass you
really want:
>
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
So to go from
getModel(FooModel.class);
To
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
You would apply a second rule AND you would ONLY run this rule
against
your utility classes so that you would not otherwise affect yourViewBean
and Model classes which are completely fine with the simplegetModel call.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getModel\(]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getModel\(]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getRequestContext().getModelManager().getModel(]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
A similer rule can be applied to getSession and other CSpider APIcalls.
For instance here is the rule for converting getSession calls toleverage
the RequestManager.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getSession().]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
----- Original Message -----
From: "Matthew Stevens" <matthew.stevens@e...>
Sent: Tuesday, August 07, 2001 12:56 PM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has
the
details
on various tactics of migrating these type of utilities.
Essentially,
you
either need to convert these utilities to Models themselves or
keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of customhelper
method
as a replacement whicch uses JDBC results instead of
CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes.
These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do themanipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion forthese
utilities we have to do manually.
My question is Can we access the the models in the postmigration
sameway or do we need requestContext?
We have lots of utility classes which are DataObjectintensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected]
[Non-text portions of this message have been removed]
[email protected]
[email protected]Namburi,
When you said you used the Reg Exp tool, did you use it only as
preconfigured by the iMT migrate application wizard?
Because the default configuration of the regular expression tool will only
target the files in your ND project directories. If you wish to target
classes outside of the normal directory scope, you have to either modify the
"Source Directory" property OR create another instance of the regular
expression tool. See the "Tool" menu in the iMT to create additional tool
instances which can each be configured to target different sets of files
using different sets of rules.
Usually, I utilize 3 different sets of rules files on a given migration:
spider2jato.xml
these are the generic conversion rules (but includes the optimized rules for
ViewBean and Model based code, i.e. these rules do not utilize the
RequestManager since it is not needed for code running inside the ViewBean
or Model classes)
I run these rules against all files.
See the file download section of this forum for periodic updates to these
rules.
nonProjectFileRules.xml
these include rules that add the necessary
RequestManager.getRequestContext(). etc prefixes to many of the common
calls.
I run these rules against user module and any other classes that do not are
not ModuleServlet, ContainerView, or Model classes.
appXRules.xml
these rules include application specific changes that I discover while
working on the project. A common thing here is changing import statements
(since the migration tool moves ND project code into different jato
packaging structure, you sometime need to adjust imports in non-project
classes that previously imported ND project specific packages)
So you see, you are not limited to one set of rules at all. Just be careful
to keep track of your backups (the regexp tool provides several options in
its Expert Properties related to back up strategies).
----- Original Message -----
From: <vnamboori@y...>
Sent: Wednesday, August 08, 2001 6:08 AM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes - Pease don't
forget about the regular expression potential
Thanks Matt, Mike, Todd
This is a great input for our migration. Though we used the existing
Regular Expression Mapping tool, we did not change this to meet our
own needs as mentioned by Mike.
We would certainly incorporate this to ease our migration.
Namburi
--- In iPlanet-JATO@y..., "Todd Fast" <toddwork@c...> wrote:
All--
Great response. By the way, the Regular Expression Tool uses thePerl5 RE
syntax as implemented by Apache OROMatcher. If you're doing lotsof these
sorts of migration changes manually, you should definitely buy theO'Reilly
book "Mastering Regular Expressions" and generate some rules toautomate the
conversion. Although they are definitely confusing at first,regular
expressions are fairly easy to understand with some documentation,and are
superbly effective at tackling this kind of migration task.
Todd
----- Original Message -----
From: "Mike Frisino" <Michael.Frisino@S...>
Sent: Tuesday, August 07, 2001 5:20 PM
Subject: Re: [iPlanet-JATO] Use Of models in utility classes -Pease don't
forget about the regular expression potential
Also, (and Matt's document may mention this)
Please bear in mind that this statement is not totally correct:
Since the migration tool does not do much of conversion for
these
utilities we have to do manually.Remember, the iMT is a SUITE of tools. There is the extractiontool, and
the translation tool, and the regular expression tool, and severalother
smaller tools (like the jar and compilation tools). It is correctto state
that the extraction and translation tools only significantlyconvert the
primary ND project objects (the pages, the data objects, and theproject
classes). The extraction and translation tools do minimumtranslation of the
User Module objects (i.e. they repackage the user module classes inthe new
jato module packages). It is correct that for all other utilityclasses
which are not formally part of the ND project, the extraction and
translation tools do not perform any migration.
However, the regular expression tool can "migrate" any arbitrary
file
(utility classes etc) to the degree that the regular expressionrules
correlate to the code present in the arbitrary file. So first andforemost,
if you have alot of spider code in your non-project classes youshould
consider using the regular expression tool and if warranted adding
additional rules to reduce the amount of manual adjustments thatneed to be
made. I can stress this enough. We can even help you write theregular
expression rules if you simply identify the code pattern you wish to
convert. Just because there is not already a regular expressionrule to
match your need does not mean it can't be written. We have notnearly
exhausted the possibilities.
For example if you say, we need to convert
CSpider.getDataObject("X");
To
RequestManager.getRequestContext().getModelManager().getModel(XModel.class);
Maybe we or somebody else in the list can help write that regularexpression if it has not already been written. For instance in thelast
updated spider2jato.xml file there is already aCSpider.getCommonPage("X")
rule:
<!--getPage to getViewBean-->
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getViewBean($1ViewBean.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
Following this example a getDataObject to getModel would look
like this:
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getModel($1Model.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
In fact, one migration developer already wrote that rule andsubmitted it
for inclusion in the basic set. I will post another upgrade to thebasic
regular expression rule set, look for a "file uploaded" posting.Also,
please consider contributing any additional generic rules that youhave
written for inclusion in the basic set.
Please not, that in some cases (Utility classes in particular)
the rule
application may be more effective as TWO sequention rules ratherthan one
monolithic rule. Again using the example above, it will convert
CSpider.getDataObject("Foo");
To
getModel(FooModel.class);
Now that is the most effective conversion for that code if that
code is in
a page or data object class file. But if that code is in a Utilityclass you
really want:
>
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
So to go from
getModel(FooModel.class);
To
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
You would apply a second rule AND you would ONLY run this rule
against
your utility classes so that you would not otherwise affect yourViewBean
and Model classes which are completely fine with the simplegetModel call.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getModel\(]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getModel\(]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getRequestContext().getModelManager().getModel(]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
A similer rule can be applied to getSession and other CSpider APIcalls.
For instance here is the rule for converting getSession calls toleverage
the RequestManager.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getSession().]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
----- Original Message -----
From: "Matthew Stevens" <matthew.stevens@e...>
Sent: Tuesday, August 07, 2001 12:56 PM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has
the
details
on various tactics of migrating these type of utilities.
Essentially,
you
either need to convert these utilities to Models themselves or
keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of customhelper
method
as a replacement whicch uses JDBC results instead of
CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes.
These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do themanipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion forthese
utilities we have to do manually.
My question is Can we access the the models in the postmigration
sameway or do we need requestContext?
We have lots of utility classes which are DataObjectintensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected]
[Non-text portions of this message have been removed]
[email protected]
[email protected] -
Re: [iPlanet-JATO] Use Of models in utility classes
Hi Matt,
Sounds like some of the stuff we need to migrate has a lot in common with
Namburi's project.
I would be very keen to get hold of a copy of the 'tactic' document you
mention below, as well as the sample code you mention to replace CspDBResult
stuff with JDBC results.
Thanks in advance,
Phil
----- Original Message -----
From: Matthew Stevens <matthew.stevens@E...>
Sent: Wednesday, August 08, 2001 7:56 AM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has thedetails
on various tactics of migrating these type of utilities. Essentially, you
either need to convert these utilities to Models themselves or keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of custom helper method
as a replacement whicch uses JDBC results instead of CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100253094145066046167121181">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes. These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do the manipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion for these
utilities we have to do manually.
My question is Can we access the the models in the post migration
sameway or do we need requestContext?
We have lots of utility classes which are DataObject intensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected]Hi Matt,
Sounds like some of the stuff we need to migrate has a lot in common with
Namburi's project.
I would be very keen to get hold of a copy of the 'tactic' document you
mention below, as well as the sample code you mention to replace CspDBResult
stuff with JDBC results.
Thanks in advance,
Phil
----- Original Message -----
From: Matthew Stevens <matthew.stevens@E...>
Sent: Wednesday, August 08, 2001 7:56 AM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has thedetails
on various tactics of migrating these type of utilities. Essentially, you
either need to convert these utilities to Models themselves or keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of custom helper method
as a replacement whicch uses JDBC results instead of CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100253094145066046167121181">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes. These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do the manipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion for these
utilities we have to do manually.
My question is Can we access the the models in the post migration
sameway or do we need requestContext?
We have lots of utility classes which are DataObject intensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected] -
SOAP oracle xml sql utility class definition not found error
I have created a java class that connects to database using JDBC runs an sql statement and produces xml using Oracle XML SQL Utility class. The java class works perfectly when I deploy it as a soap web service and try to run through SOAP server it gives a SOAP error oracle/xml/sql/query/OracleXML/Query [java.lang.NoClassDefFoundError].
Can anyone help please.
Thanks
AlinaSounds like you have not included the xsu12.jar file in the server-side CLASSPATH.
This depends also on the xmlparserv2.jar and on the Oracle JDBC driver. Later versions
of XSU may also depend on the xdb.jar file, too. -
ClassNotFoundException on utility class in JTA Transaction
When using user defined transactions, I am finding I get odd
ClassNotFoundExceptions. I've tested this primarily on NT/2000, but did
also confirm it on Solaris. Can anyone explain it?
The exception only seems to occur if it becomes necessary to throw an
exception from the EJB. If I am not inside a user defined transaction,
there are no problems. (Even if the method is marked as Transacation
Required). Similarly, if no exception is thrown, there is also no problem
(even though I use plenty of other utility classes)
The classes (including the utility class) are all in my deployed jar file
(which is deployed as part of an ear file).
The error message is below:
java.lang.ClassNotFoundException:
com.iknowledge.inext.exception.STInvalidNameException
at
weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.
java:178)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at
weblogic.j2ee.ApplicationManager.loadFromNetwork(ApplicationManager.java:248
at
weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:175)
at
weblogic.rjvm.MsgAbbrevInputStream.readClassDescriptor(MsgAbbrevInputStream.
java:211)
at
weblogic.common.internal.ChunkedObjectInputStream$NestedObjectInputStream.re
adClassDescriptor(ChunkedObjectInputStream.java:290)
at
java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:906)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:366)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1186)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
at
java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2263)
at
java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519)
at
java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1412)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
at
weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectIn
putStream.java:107)
at
weblogic.transaction.internal.PropagationContext.readExternal(PropagationCon
text.java:304)
at
weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectIn
putStream.java:97)
at
weblogic.common.internal.ChunkedObjectInputStream.readObjectWL(ChunkedObject
InputStream.java:123)
at
weblogic.rjvm.MsgAbbrevInputStream.readTxContext(MsgAbbrevInputStream.java:1
66)
at
weblogic.rjvm.MsgAbbrevInputStream.readMessageContext(MsgAbbrevInputStream.j
ava:156)
at
weblogic.rjvm.ConnectionManager.dispatch(ConnectionManager.java:581)
at
weblogic.rjvm.t3.T3JVMConnection.dispatch(T3JVMConnection.java:454)
at
weblogic.socket.NTSocketMuxer.processSockets(NTSocketMuxer.java:638)
at
weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:24)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
You closed your Main class with a bracket, so your getConnection() method isn't in a class
public class Main {
/** Creates a new instance of Main */
public Main() {
public static void main(String[] args) {
Connection con = getConnection();
System.out.println("The connection is: " +con );
}That is your entire Main class. Anything below it isn't in the class. -
Is jdbc thin driver not designed for internet use?
Is jdbc thin driver not designed for internet use?
The size of the thin-driver file is about 1MB of size and is
too large if were to ask clients to download it from the
internet.
Can anyone advise on this issue?
nullYou need to remote onto the server and go into start->control panel-Administration-> ODBC (or sometimes start->administration->ODBC) and set up ODBC connections . Make sure you set them up on the system tab, then you should see them in EAS. I don't remember, b ut don't think you need to restart the Essbase servise for them to take effect
-
Any reported problems using jdbc over a WAN?
If im trying to connect to a Database that's on a WAN will I experience any issues in using jdbc to connect and execute queries to that database?
I know problems would come up if my wan network is slow, but has jdbc been able to handle long distance database queries? timeout values?but why?
is it because of security? If a company had a database with your personal info hanging out on the Web for anyone to query without any validation or security, how would you feel about it?
design pattern issues? It's just good layered design.
just doesnt make sense?Not in my opinion.
have u experienced/heard of any problems of
connecting to a database over a WAN and executing
queries?You don't say anything about who the client is. If the database is behind a firewall, outside clients shouldn't be able to access the port where the listener is running. Only port 80 should be open on that firewall.
So you either write a servlet that listens on port 80 for HTTP requests from a browser-based client OR you ask your firewall admin to punch a hole in the firewall and open up the port on which your database is listening for queries and use a Swing client.
If s/he agrees to do it, quit immediately. It means your company doesn't know anything about security.
% -
Creating self registration request using OIM API
Hi guys,
When we try to create a self regisrtation request using OIM API , we ge the following exception:
We get this error when we set the following in Design console.
Does user have to provide challenge information during registration = FALSE
and passed an blank object in place of challenge question parameter in createSelfRegistrationRequest method in tcUtilityBaseClass.
19:22:17,218 ERROR [REQUESTS] Error: Failed to save REQ_CONSOLIDATED_DATA_VALUE
data for Create Entity.
java.lang.NullPointerException
at org.apache.xml.serializer.TreeWalker.dispatachChars(TreeWalker.java:2
44)
at org.apache.xml.serializer.TreeWalker.startNode(TreeWalker.java:414)
at org.apache.xml.serializer.TreeWalker.traverse(TreeWalker.java:143)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(Transf
ormerIdentityImpl.java:389)
at com.thortech.xl.dataobj.util.RequestDataConsolidator.convertNodeToXML
(Unknown Source)
at com.thortech.xl.dataobj.util.RequestDataConsolidator.addUser(Unknown
Source)
at com.thortech.xl.dataobj.tcDataBase.createRequestForCreateEntity(Unkno
wn Source)
at com.thortech.xl.dataobj.tcDataBase.createRegistrationRequest(Unknown
Source)
at com.thortech.xl.dataobj.tcDataBase.createRegistrationRequest(Unknown
Source)
at com.thortech.xl.ejb.beansimpl.tcUnauthenticatedOperationsBean.createR
egistrationRequest(Unknown Source)
at com.thortech.xl.ejb.beans.tcUnauthenticatedOperationsSession.createRe
gistrationRequest(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.invocation.Invocation.performCall(Invocation.java:359)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
tatelessSessionContainer.java:237)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
ke(CachedConnectionInterceptor.java:158)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
elessSessionInstanceInterceptor.java:169)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidation
Interceptor.java:63)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
rceptor.java:121)
How do we create a self registration request , using OIM API , with and without challenge questions?Well try this piece of code. This might be similar to yours but it worked perfectly for me. For you the error might be the attribute names which you are passing, it should be the one dfined in the FormMetaData xml as below.
import Thor.API.tcUtilityFactory;
// define you class below
ConfigurationClient.ComplexSetting config = ConfigurationClient.getComplexSettingByPath("Discovery.CoreServer");
final Hashtable env = config.getAllSettings();
Hashtable quesAns = new Hashtable();
HashMap user = new HashMap();
user.put("Users.User ID", "SelfTesting");
user.put("Users.First Name", "SelfTesting");
user.put("Users.Last Name", "SelfTesting");
user.put("Users.Email", "[email protected]");
user.put("Users.Password", "SelfTesting");
user.put("ConfirmPassword", "SelfTesting");
tcUtilityFactory.createRegistrationRequest(env, user, quesAns);
And for the query of challenge QnA, these are the following combinations possible:
1) Property Does user have to provide challenge information during registration set to TRUE
- During self-registration from web console, it will show you Challenge Questions section on the right. If you do not select any questions, it will thow you an error there itself.
- Doing it from API will create no difference(even if you pass a blank HashTable). The request will be created successfully and on completion when the user tries to login, it will ask for Security QnA.
2) Property Does user have to provide challenge information during registration set to FALSE
- During self-registration from web console, it doesn't show you Challenge Questions section on the right. The request will be created successfully and on completion when the user tries to login, it will ask for Security QnA.
- Doing it from API, you will have to pass a blank HashTable as in above code. The request will be created successfully and on completion when the user tries to login, it will ask for Security QnA.
Hope it works.
Thanks
Sunny -
Using JDBC to write a DAT file with delimiters to a database
Hi Everybody
I am new to JDBC and i am trying out some small applications: I downloaded this small program and tried to compile it and and I got the following errors: ( I have MySql installed). I have to set the classpath for the driver. But I am not sure why I am gettting the NullPointerException though)
I will be very gratefull to your help. Thanks a lot..
Loading JDBC Driver -> oracle.jdbc.driver.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at us.ilango.WriteFileToTable.<init>(WriteFileToTable.java:69)
at us.ilango.WriteFileToTable.main(WriteFileToTable.java:367)
java.lang.NullPointerException
at us.ilango.WriteFileToTable.createTable(WriteFileToTable.java:97)
at us.ilango.WriteFileToTable.main(WriteFileToTable.java:368)
Exception in thread "main"
the Program is as follows:
package us.ilango;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
* The following class provides an example of how to read a simple text file
* of records and then insert them into a table in a database. A text file
* named Employee.txt will contain employee records to be inserted into the
* following table:
* SQL> desc emp
* Name Null? Type
* EMP_ID NOT NULL NUMBER
* DEPT_ID NUMBER
* NAME NOT NULL VARCHAR2(30)
* DATE_OF_BIRTH NOT NULL DATE
* DATE_OF_HIRE NOT NULL DATE
* MONTHLY_SALARY NOT NULL NUMBER(15,2)
* POSITION NOT NULL VARCHAR2(100)
* EXTENSION NUMBER
* OFFICE_LOCATION VARCHAR2(100)
* NOTE: This example will provide and call a method that creates the EMP
* table. The name of the method is called createTable() and is called
* from the main() method.
public class WriteFileToTable {
final static String driverClass = "oracle.jdbc.driver.OracleDriver";
final static String connectionURL = "jdbc:oracle:thin:@localhost:1521:CUSTDB";
final static String userID = "scott";
final static String userPassword = "tiger";
final static String inputFileName = "Employee.txt";
final static String TABLE_NAME = "EMP";
final static String DELIM = ",";
Connection con = null;
* Construct a WriteFileToTable object. This constructor will create an
* Oracle database connection.
public WriteFileToTable() {
try {
System.out.print(" Loading JDBC Driver -> " + driverClass + "\n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "\n");
this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
System.out.print(" Connected as -> " + userID + "\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
* Method used to create the initial EMP table. Before attempting to create
* the table, this method will first try to drop the table.
public void createTable() {
Statement stmt = null;
try {
stmt = con.createStatement();
System.out.print(" Dropping Table: " + TABLE_NAME + "\n");
stmt.executeUpdate("DROP TABLE " + TABLE_NAME);
System.out.print(" - Dropped Table...\n");
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
System.out.print(" - Table " + TABLE_NAME + " did not exist.\n");
try {
stmt = con.createStatement();
System.out.print(" Creating Table: " + TABLE_NAME + "\n");
stmt.executeUpdate("CREATE TABLE emp (" +
" emp_id NUMBER NOT NULL " +
" , dept_id NUMBER " +
" , name VARCHAR2(30) NOT NULL " +
" , date_of_birth DATE NOT NULL " +
" , date_of_hire DATE NOT NULL " +
" , monthly_salary NUMBER(15,2) NOT NULL " +
" , position VARCHAR2(100) NOT NULL " +
" , extension NUMBER " +
" , office_location VARCHAR2(100))");
System.out.print(" - Created Table...\n");
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
* Method used to read records from Employee.txt file then write the records
* to an Oracle table within the database named "EMP".
public void performLoadWrite() {
Statement stmt = null;
int insertResults = 0;
StringTokenizer st = null;
String emp_id;
String dept_id;
String name;
String date_of_birth;
String date_of_hire;
String monthly_salary;
String position;
String extension;
String office_location;
try {
System.out.print(" Creating Statement...\n");
stmt = con.createStatement ();
System.out.print(" Create FileReader Object for file: " + inputFileName + "...\n");
FileReader inputFileReader = new FileReader(inputFileName);
System.out.print(" Create BufferedReader Object for FileReader Object...\n");
BufferedReader inputStream = new BufferedReader(inputFileReader);
String inLine = null;
while ((inLine = inputStream.readLine()) != null) {
st = new StringTokenizer(inLine, DELIM);
emp_id = st.nextToken();
dept_id = st.nextToken();
name = st.nextToken();
date_of_birth = st.nextToken();
date_of_hire = st.nextToken();
monthly_salary = st.nextToken();
position = st.nextToken();
extension = st.nextToken();
office_location = st.nextToken();
System.out.print(" Inserting value for [" + name + "]\n");
insertResults = stmt.executeUpdate(
"INSERT INTO " + TABLE_NAME + " VALUES (" +
emp_id +
" , " + dept_id +
" , '" + name + "'" +
" , '" + date_of_birth + "'" +
" , '" + date_of_hire + "'" +
" , " + monthly_salary +
" , '" + position + "'" +
" , " + extension +
" , '" + office_location + "')");
System.out.print(" " + insertResults + " row created.\n");
System.out.print(" Commiting Transaction...\n");
con.commit();
System.out.print(" Closing inputString...\n");
inputStream.close();
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
* Method used to query records from the database table EMP. This method
* can be used to verify all records have been correctly loaded from the
* example text file "Employee.txt".
public void queryRecords() {
Statement stmt = null;
ResultSet rset = null;
int deleteResults = 0;
int rowNumber = 0;
int emp_id;
int dept_id;
String name;
String date_of_birth;
Date date_of_birth_p;
String date_of_hire;
Date date_of_hire_p;
float monthly_salary;
String position;
int extension;
String office_location;
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
NumberFormat defaultFormat = NumberFormat.getCurrencyInstance();
System.out.print(" Creating Statement...\n");
stmt = con.createStatement ();
System.out.print(" Opening query for table: " + TABLE_NAME + "...\n");
rset = stmt.executeQuery ("SELECT * FROM emp ORDER BY emp_id");
while (rset.next ()) {
rowNumber = rset.getRow();
emp_id = rset.getInt(1);
if ( rset.wasNull() ) {emp_id = -1;}
dept_id = rset.getInt(2);
if ( rset.wasNull() ) {dept_id = -1;}
name = rset.getString(3);
if ( rset.wasNull() ) {name = "<null>";}
date_of_birth = rset.getString(4);
if ( rset.wasNull() ) {date_of_birth = "1900-01-01";}
try {
date_of_birth_p = formatter.parse(date_of_birth);
} catch (ParseException e) {
date_of_birth_p = new Date(0);
date_of_hire = rset.getString(5);
if ( rset.wasNull() ) {date_of_hire = "1900-01-01";}
try {
date_of_hire_p = formatter.parse(date_of_hire);
} catch (ParseException e) {
date_of_hire_p = new Date(0);
monthly_salary = rset.getFloat(6);
if ( rset.wasNull() ) {monthly_salary = 0;}
position = rset.getString(7);
if ( rset.wasNull() ) {position = "<null>";}
extension = rset.getInt(8);
if ( rset.wasNull() ) {extension = -1;}
office_location = rset.getString(9);
if ( rset.wasNull() ) {office_location = "<null>";}
System.out.print(
"\n" +
" RESULTS -> [R" + rowNumber + "] " + "\n" +
" Employee ID : " + emp_id + "\n" +
" Department ID : " + dept_id + "\n" +
" Employee Name : " + name + "\n" +
" D.O.B. : " + date_of_birth_p + "\n" +
" Date of Hire : " + date_of_hire_p + "\n" +
" Monthly Salary : " + defaultFormat.format(monthly_salary) + "\n" +
" Position : " + position + "\n" +
" Extension : x" + extension + "\n" +
" Office Location : " + office_location +
"\n");
System.out.print(" Closing ResultSet...\n");
rset.close();
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
* Close down Oracle connection.
public void closeConnection() {
try {
System.out.print(" Closing Connection...\n");
con.close();
} catch (SQLException e) {
e.printStackTrace();
* Sole entry point to the class and application.
* @param args Array of String arguments.
* @exception java.lang.InterruptedException
* Thrown from the Thread class.
public static void main(String[] args)
throws java.lang.InterruptedException {
WriteFileToTable runExample = new WriteFileToTable();
runExample.createTable();
runExample.performLoadWrite();
runExample.queryRecords();
runExample.closeConnection();
}Hi
Thanks a lot. I ran the program with the MySql driver as follows:
The errors are as follows: I will ttry to place the Driver in the Classpath. As far as I know the driver has been specified correctly this time.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at us.ilango.WriteAntennas.<init>(WriteAntennas.java:41)
at us.ilango.WriteAntennas.main(WriteAntennas.java:377)
java.lang.NullPointerException
at us.ilango.WriteAntennas.createTable(WriteAntennas.java:70)
at us.ilango.WriteAntennas.main(WriteAntennas.java:378)
Exception in thread "main" Loading JDBC Driver -> com.mysql.jdbc.Driver
The program is as follows:
package us.ilango;
* @author ilango
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
public class WriteAntennas {
final static String driverClass = "com.mysql.jdbc.Driver";
final static String connectionURL = "jdbc:mysql://localhost/test2";
final static String userID = "brian";
final static String userPassword = " ";
final static String inputFileName = "CO.DAT";
final static String TABLE_NAME = "CELL";
final static String DELIM = "|";
Connection con = null;
public WriteAntennas() {
try {
System.out.print(" Loading JDBC Driver -> " + driverClass + "\n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "\n");
this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
System.out.print(" Connected as -> " + userID + "\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
* Method used to create the initial EMP table. Before attempting to create
* the table, this method will first try to drop the table.
public void createTable() {
Statement stmt=null;
try {
stmt = con.createStatement();
System.out.print(" Dropping Table: " + TABLE_NAME + "\n");
stmt.executeUpdate("DROP TABLE " + TABLE_NAME);
System.out.print(" - Dropped Table...\n");
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
System.out.print(" - Table " + TABLE_NAME + " did not exist.\n");
try {
stmt = con.createStatement();
System.out.print(" Creating Table: " + TABLE_NAME + "\n");
stmt.executeUpdate("create table TOWER_PUBACC_CO (" +
"record_type char(2) null" +
", content_indicator char(3) null" +
", file_number char(8) null" +
", registration_number char(7) null" +
", unique_system_identifier long(9,0) not null" +
", coordinate_type char(1) not null" +
",latitude_degrees int null" +
",latitude_minutes int null" +
",latitude_seconds int(4,1) null" +
",latitude_direction char(1) null" +
",latitude_total_seconds int(8,1) null" +
",longitude_degrees int null" +
",longitude_minutes int null" +
",longitude_seconds int(4,1) null" +
",longitude_direction char(1) null" +
",longitude_total_seconds int(8,1) null)" );
System.out.print(" created Table...\n");
System.out.print(" closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
public void performLoadWrite() {
Statement stmt = null;
int insertResults = 0;
StringTokenizer st = null;
String record_type ;
String content_indicator;
String file_number ;
String registration_number;
String unique_system_identifier ;
String coordinate_type;
String latitude_degrees;
String latitude_minutes;
String latitude_seconds;
String latitude_direction;
String latitude_total_seconds;
String longitude_degrees;
String longitude_minutes;
String longitude_seconds;
String longitude_direction;
String longitude_total_seconds;
try {
System.out.print(" Creating Statement...\n");
stmt = con.createStatement ();
System.out.print(" Create FileReader Object for file: " + inputFileName + "...\n");
FileReader inputFileReader = new FileReader(inputFileName);
System.out.print(" Create BufferedReader Object for FileReader Object...\n");
BufferedReader inputStream = new BufferedReader(inputFileReader);
String inLine = null;
while ((inLine = inputStream.readLine()) != null) {
st = new StringTokenizer(inLine, DELIM);
record_type = st.nextToken();
content_indicator = st.nextToken();
file_number = st.nextToken();
registration_number = st.nextToken();
unique_system_identifier = st.nextToken();
coordinate_type =st.nextToken();
latitude_degrees = st.nextToken();
latitude_minutes = st.nextToken();
latitude_seconds=st.nextToken();
latitude_direction = st.nextToken();
latitude_total_seconds =st.nextToken();
longitude_degrees= st.nextToken();
longitude_minutes = st.nextToken();
longitude_seconds = st.nextToken();
longitude_direction=st.nextToken();
longitude_total_seconds =st.nextToken();
System.out.print(" Inserting value for [" + unique_system_identifier + "]\n");
insertResults = stmt.executeUpdate(
"INSERT INTO " + TABLE_NAME + " VALUES (" +
record_type +
" , " + content_indicator +
" , '" + file_number + "'" +
" , '" + registration_number + "'" +
" , '" + unique_system_identifier + "'" +
" , " + coordinate_type + "'" +
" , '" + latitude_degrees + "'" +
" , " + latitude_minutes + "'" +
" , '" + latitude_seconds + "'" +
" , '" + latitude_direction + "'" +
" , '" + latitude_total_seconds + "'" +
" , '" + longitude_minutes + "'" +
" , '" + longitude_seconds + "'" +
" , '" + longitude_direction + "'" +
" , '" + longitude_total_seconds + "')");
System.out.print(" " + insertResults + " row created.\n");
System.out.print(" Commiting Transaction...\n");
con.commit();
System.out.print(" Closing inputString...\n");
inputStream.close();
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
public void queryRecords() {
Statement stmt = null;
ResultSet rset = null;
int deleteResults = 0;
int rowNumber = 0;
String record_type;
String content_indicator;
String file_number;
String registration_number ;
long unique_system_identifier;
String coordinate_type ;
int latitude_degrees ;
int latitude_minutes ;
int latitude_seconds;
String latitude_direction;
int latitude_total_seconds;
int longitude_degrees;
int longitude_minutes;
int longitude_seconds;
String longitude_direction;
int longitude_total_seconds;
try {
System.out.print(" Creating Statement...\n");
stmt = con.createStatement ();
System.out.print(" Opening query for table: " + TABLE_NAME + "...\n");
rset = stmt.executeQuery ("SELECT * FROM cell ORDER BY unique_system_identifier");
while (rset.next ()) {
rowNumber = rset.getRow();
unique_system_identifier = rset.getInt (1);
if ( rset.wasNull() ) {unique_system_identifier = -1;}
record_type = rset.getString (2);
if ( rset.wasNull() ) {record_type = "<null>";}
content_indicator = rset.getString(3);
if ( rset.wasNull() ) {content_indicator = "<null>";}
file_number = rset.getString(4);
if ( rset.wasNull() ) {file_number = "<null>";}
registration_number = rset.getString(5);
if ( rset.wasNull() ) {registration_number = "<null>";}
coordinate_type = rset.getString(6);
if ( rset.wasNull() ) {coordinate_type = "<null>";}
latitude_degrees = rset.getInt(7);
if ( rset.wasNull() ) {latitude_degrees = 1;}
latitude_minutes = rset.getInt(8);
if ( rset.wasNull() ) {latitude_minutes = 1;}
latitude_seconds = rset.getInt(9);
if ( rset.wasNull() ) {latitude_seconds = 1;}
latitude_direction = rset.getString(10);
if ( rset.wasNull() ) {latitude_direction = "<null>";}
latitude_total_seconds = rset.getInt(11);
if ( rset.wasNull() ) {latitude_total_seconds = 1;}
longitude_degrees = rset.getInt(12);
if ( rset.wasNull() ) {longitude_degrees = 1;}
longitude_minutes = rset.getInt(13);
if ( rset.wasNull() ) {longitude_minutes = 1;}
longitude_seconds = rset.getInt(14);
if ( rset.wasNull() ) {longitude_seconds = 1;}
longitude_direction = rset.getString(15);
if ( rset.wasNull() ) {longitude_direction = "<null>";}
longitude_total_seconds = rset.getInt(16);
if ( rset.wasNull() ) {longitude_total_seconds = 1;}
System.out.print(
"\n" +
" RESULTS -> [R" + rowNumber + "] " + "\n" +
" Unique_System_Identifier : " + unique_system_identifier + "\n" +
" Record_type : " + record_type + "\n" +
" Content_Indicator : " + content_indicator + "\n" +
" Registration_Number : " + registration_number + "\n" +
" File_Number : " + file_number + "\n" +
" Coordinate_Type : " + coordinate_type + "\n" +
" Latitude_Degrees : " + latitude_degrees + "\n" +
" Latitude_Minutes : " + latitude_minutes + "\n" +
" Latitude_Seconds : " + latitude_seconds + "\n" +
" Latitude_Direction : " + latitude_direction + "\n" +
" Latitude_Total_Seconds : " + latitude_total_seconds + "\n" +
" Longitude_Degrees : " + longitude_degrees + "\n" +
" longitude_minutes : " + longitude_minutes + "\n" +
" Longitude_Seconds : " + longitude_seconds + "\n" +
" longitude_direction : " + longitude_direction + "\n" +
" Longitude_Total_Seconds : " + longitude_total_seconds +
"\n");
System.out.print(" Closing ResultSet...\n");
rset.close();
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
public void closeConnection() {
try {
System.out.print(" Closing Connection...\n");
con.close();
} catch (SQLException e) {
e.printStackTrace();
public static void main(String[] args)
throws java.lang.InterruptedException {
WriteAntennas runJob = new WriteAntennas();
runJob.createTable();
runJob.performLoadWrite();
runJob.queryRecords();
runJob.closeConnection();
} -
How to use JDBC Connection Pools in a standalone application?
Hi, there,
I have a question about how to use JDBC Connection Pools in an application. I know well about connection pool itself, but I am not quite sure how to keep the pool management object alive all the time to avoid being destroyed by garbage collection.
for example, at the website: http://www.developer.com/java/other/article.php/626291, there is a simple connection pool implementation. there are three classes:JDBCConnection, the application's gateway to the database; JDBCConnectionImpl, the real class/object to provide connection; and JDBCPool, the management class to manage connection pool composed by JDBCConnectionImpl. JDBCPool is designed by Singleton pattern to make sure only one instance. supposing there is only one client to use connection for many times, I guess it's ok because this client first needs instantiate JDBCPool and JDBCConnectionImpl and then will hold the reference to JDBCPool all the time. but how about many clients want to use this JDBCPool? supposing client1 finishes using JDBCPool and quits, then JDBCPool will be destroyed by garbage collection since there is no reference to it, also all the connections of JDBCConnectionImpl in this pool will be destroyed too. that means the next client needs recreate pool and connections! so my question is that if there is a way to keep pool management instance alive all the time to provide connection to any client at any time. I guess maybe I can set the pool management class as daemon thread to solve this problem, but I am not quite sure. besides, there is some other problems about daemon thread, for example, how to make sure there is only one daemon instance? how to quit it gracefully? because once the whole application quits, the daemon thread also quits by force. in that case, all the connections in the pool won't get chance to close.
I know there is another solution by JNDI if we develop servlet application. Tomcat provides an easy way to setup JNDI database pooling source that is available to JSP and Servlet. but how about a standalone application? I mean there is no JNDI service provider. it seems a good solution to combine Commons DBCP with JNID or Apache's Naming (http://jakarta.apache.org/commons/dbcp/index.html). but still, I don't know how to keep pool management instance alive all the time. once we create a JNDI enviroment or naming, if it will save in the memory automatically all the time? or we must implement it as a daemon thread?
any hint will be great apprieciated!
SamTo my knoledge the pool management instance stays alive as long as the pool is alive. What you have to figure out is how to keep a reference to it if you need to later access it.
-
To run a report from command line, when using jdbc-odbc bridge
Hi,
How to run a report from command line, when using jdbc-odbc bridge?
Usually with tns, we do by "rwrun module=<> userid=<user>/<passwd>@tns".
with odbc, we do by "rwrun module=<> userid=<user>/<passwd>@odbc:DSN"
Please specify, what is command line arguments for jdbc-odbc bridge driver?
Environment : Oracle 9i Report Builder on WinNT
Database : Sybase
Regards,
RamananHello Ramanan,
Report Builder : connect JDBC Query in Report Builder is to through Connection Dialog in JDBC Query Editor. User can use a Sign on parameter (can use, default : P_JDBCPDS or can create new) to connect to JDBC Data Source. Connection once made will be mentioned and will be reused through out Reports Builder.
JDBC PDS allows user to connect one or more same or different kind of databases.
While running report through runtime or Server, user can pass the sign on parameter(connection string) value, like any other user parameter.
Syntax for connection string : <username>/<password>@databaseURL . The syntax of database part of connection string depend on the type of JDBC Driver used to connect to Data Source while designing the JDBC Query. databaseURL refer to the location of the database and its format depend on the JDBCPDS river selected in design time while creating the JDBC Query.
rwrun eg :
rwrun report=jdbc_odbc.rdf destype=file desname=output.html desformat=html P_JDBCPDS=scott/tiger@database
Server eg :
http://server.com:8888/servlet/RWServlet?server=MyReportServer+report=jdbc_odbc.rdf+destype=cache+desformat=html+P_JDBCPDS=scott/tiger@database
http :
Please see ORACLE_HOME/reports/conf/jdbcpds.conf for more information.
With Regards
Reports Team -
Error while updating database using jdbc receiver adapter
Hi All,
I am trying to update a single record using jdbc receiver adapter.
This is my the message that is getting created..
<?xml version="1.0" encoding="UTF-8" ?>
- <ns0:Data xmlns:ns0="urn:Test">
- <STATEMENT>
- <TABLENAME ACTION="UPDATE_INSERT">
<TABLE>ORDERS</TABLE>
- <ACCESS>
<OrderID>99999</OrderID>
<CustomerID>VICTE</CustomerID>
<EmployeeID>3</EmployeeID>
<ShipAddress>VICTE</ShipAddress>
</ACCESS>
- <KEY>
<OrderID compareOperation="EQ">99999</OrderID>
<ShipAddress compareOperation="EQ">VICTE</ShipAddress>
</KEY>
</TABLENAME>
</STATEMENT>
</ns0:Data>
But in Adapter Monitoring i am getting the following error..
<i>Error while parsing or executing XML-SQL document: Error processing request in sax parser: Error when executing statement for table/stored proc. 'ORDERS' (structure 'STATEMENT'): java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'VICTE'.</i>
Regards,
RahulRahul,
> In this case i believe the interface has to be synch.
> So what will the response message type be like..
Not necessary. UPDATE can be asynch as well.
Can you turn the trace on like pointed by Michal and then you can see the Query in the Audit Log of the adapter montioring. Try to execute the same query from your DB Client like TOAD and see what is the Syntax error you are getiing.!
The problem looks like some field has some dataype / column name mismatch.
Regards
Bhavesh -
Creation of tables using JDBC or SQLJ in webdynpro application
Hi,
I am trying to create tables in javadictionary(MaxDB)using my WebDynpro application.I tried creating tables using SQLJ and JDBC.But I was not able to do it.I can select and insert data into already created tables.
Whwn I tried creating a table using JDBC I encountered the following exception.
com.sap.sql.log.OpenSQLException: The SQL statement "CREATE TABLE TMP_DEPID (DEPID varchar(10) NOT NULL,DEPNAME VARCHAR(25))" contains the syntax error[s]: Open SQL syntax error: CREATE ... TABLE is not supported
SQL syntax error: "VARCHAR" is a reserved keyword and cannot be used as an unquoted identifier
Does this mean that creating tables is not supported?
Can anyone help me in this matter?
Thanks in advance,
regards
~Pradeep ShettyHi Pradeep,
Yes, OpenSQL does not support creation of tables. But why would you need to create tables at runtime?! The natural way is to create the model at design time of your application, i.e. with the Java DataDictionary.
However, if for any reason you really need to create database tables at runtime, you can achieve this by using a non-OpenSQL datasource, e.g. you could create a VendorSQL one and use it to obtain JDBC connections in your app. See also http://help.sap.com/saphelp_nw04/helpdata/en/c0/3ad4d5cdc66447a188b582aad537d3/frameset.htm.
Hope that helps!
Vladimir -
Use jdbc to connect servlet to oracle 8.1.6 database on win2k
The code is below:
package moreservlets;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet used to test JDBC connection. */
public class TitleQueries extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Connecting to Database";
DriverManager.registerDriver (new
oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@pc840:1521:orcl", "scott", "tiger");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery
("select ename from emp");
while (rset.next()) {
String name = rset.getString("ename");
out.println(ServletUtilities.headWithTitle(title) +
"<body bgcolor=\"#FDF5E6\">\n" +
"<h1 align=\"center\">" + name + "</h1>\n" +
"</body></html>");
CLASSPATH=.;C:\J2ee;C:\j2sdkee1.3.1\lib\cloudscape;C:\Program Files\Apache Tomcat 4.0\common\lib\servlet.jar;C:\Oracle\Ora81\orb\classes\yoj.jar;C:\Oracle\Ora81\orb\classes\share.zip
My code cannot find the JDBC driver. Any suggestions?
Thanks.
I get the following errors:
C:\J2ee\moreservlets>javac -d "C:\Program Files\Apache Tomcat 4.0\webapps\ROOT\
EB-INF\classes" TitleQueries.java
TitleQueries.java:19: package oracle.jdbc.driver does not exist
oracle.jdbc.driver.OracleDriver());
^
TitleQueries.java:31: cannot resolve symbol
symbol : variable name
location: class moreservlets.TitleQueries
"<h1 align=\"center\">" + name + "</h1>\n" +
^
2 errorsI changed my classpath variable and my servlet
compiles okay with the:
"import oracle.jdbc.driver.*" statement.
However, I still get the following error.
Why can't it find the jdbc driver, since it finds the
import statement?
Apache Tomcat/4.0.3
Error loading driver: java.lang.ClassNotFoundException: oracle.jdbc.driver.Oracl
eDriver
WebappClassLoader: Resource '/WEB-INF/classes/moreservlets/ServletUtilities.cl
ass' was modified; Date is now: Tue Jul 02 09:57:26 CDT 2002 Was: Tue Jul 02 09:
37:20 CDT 2002
Error loading driver: java.lang.ClassNotFoundException: oracle.jdbc.driver.Oracl
eDriver
CLASSPATH=.;C:\J2ee;C:\j2sdkee1.3.1\lib\cloudscape\RmiJdbc;C:\Program Files\Apache Tomcat 4.0\common\lib\servlet.jar;C:\Oracle\Ora81\jdbc\lib\classes12.zip;C:\Oracle\Ora81\orb\classes\yoj.jar;C:\Program Files\Oracle\JDeveloper 3.2.3\jdbc\lib\oracle8.1.7\classes12.zip;C:\Oracle\Ora81\orb\classes\share.zip
//code begins here
package moreservlets;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import oracle.jdbc.driver.*;
public class TitleQueries extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@pc840:1521:orcl", "scott", "tiger");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery
("select * from emp");
out.println(ServletUtilities.headWithTitle(title) +
"<body bgcolor=\"#FDF5E6\">");
while (rset.next()) {
out.println("<h1 align=\"center\">"
+ rset.getString("ename") + "</h1>\n");
out.println("</body></html>");
catch(ClassNotFoundException cnfe) {
System.err.println("Error loading driver: " + cnfe);
catch(SQLException sqle) {
System.err.println("Error connecting: " + sqle);
}
Maybe you are looking for
-
BO XI 3.1 DeskI report Calculation mismatch
Hi , I have an Calculation issue in one report after migrated from BO 5.1.6 to BO XI 3.1. After refreshing two reports parallelly, BO XI 3.1 report 1st 3 records of two columns are not at all there in BO 5.1.6 report. in XI 3.1 i am getting 3 more re
-
Setting up a Network form my work to my home computer: Both are Macs
I have a Dual-Core Intel Xeon at work and a MacBook Pro at home. I want to be able to access my office computer from home. Is there a complete step y ste setup guide somewhere to talk me through exactly what needs to be done? I have a home network wh
-
Spilled tea on iBook, help!
My daughter knocked over a cup of tea onto my laptop, and I can't get it to start up again. Not much liquid got onto the computer, and what was visible, I dried immediately. I tried booting it off the install CD, but it can't find the hard drive. Res
-
Issues upgrading Mac OS to 10.9.5?
I'm holding off on updating my Mac Pro to 10.9.5 - don't want a repeat of the 10.9.3 issues. Can anyone confirm that 10.9.5 is safe for Premiere Pro 2014?
-
Lightroom doesn't work after update to CC 2014
After last update to CC 2014, Lightroom doesn't work for me. I use Windows 8.1