Database access code in objects constructor, or in data access object
Given an object that is stored in a database, is it better to have the database access code in a constructor method, or a data access layer object? E.g. I have a Person class
public class Person{
int Id;
String name;
int age;
}When I want to read a person's details from the database, I could use a constructor something like this:
public Person(int id){
Connection con = getDatabaseConnection();
ResultSet rs = con.createStatement().executeQuery("Select name, age from person where person_id = " + id);
rs.next();
this.name = rs.getString(1);
this.age=rs.getInt(2);
}Or I could use a method in a data access object :
public Person getPerson(int id){
Person p = new Person();
Connection con = getDatabaseConnection();
ResultSet rs = con.createStatement().executeQuery("Select name, age from person where person_id = " + id);
rs.next();
p.setName(rs.getString(1));
p.setAge(rs.getInt(2));
return p;
}It seems to me that the constructor approach has two advantages
(1) the SQL code is kept in the relevant class (so if I want to add a field to Person, I only have to make changes to the Person class)
(2) I don't have to have a setter method for each field
Is one or other of these ways generally recognized as 'best practise'?
malcolmmc wrote:
But then, on the other hand, everytime a Person gains a new field that's two places you have to change it. if the persistence interface is written in terms of the object and uses ORM, I don't have to touch the implementation. all i have to do is update the object, the database, and the mapping - just like you and your home brew ORM.
besides, so what? i'd fear the resource leak, bad layering, more difficult testing more.
Actually lately I've used annotations to label setters with database field names and run a simple home brew ORM to convert rows into objects even when not using a more complex persistence manager.home brew ORM? why is that necessary when you can choose from hibernate, ibatis, jdo, jpa, etc.? that's just nuts.
%
Similar Messages
-
Data Access Objects : JDBC Driver Not Found
Hi,
I am having a strange problem accessing JDBC Driver ( for Informix Database, if this
information helps )
I am using Data Access Objects ( DAOs ) to fetch multiple records.
The DAO is accessed from Session Bean for this case.
The constructor of the DAO does the JNDI lookup for the TxDataSource
and set it to a class attribute of the DAO. This DataSource is pointing
to a connection pool
In the getConnection() private method if DAO we use this DataSource
to pickup a onnection from the pool and fire a sql query.
This public method say getMultipleRecords( query conditions ) of DAO
returns a number of macthing records to the Session Bean.
This approach works fine in general. But sometimes I get an
java.sql.SQLException
SQLException ERROR MESSAGE is:
"Error accessing jdbc driver: driverURL = jdbc:weblogic:pool:myConnPool, props= {enableTwoPhaseCommit=true,
connectionPoolID=myConnPool}"
Once this exception occurs every time the method is called the same exception keep
coming.
Once I restart the server this API starts working again.
Could anyone give any reason why this exception might occur.
Please send an e-mail to [email protected] while replying to this message.
Thanks in advance
GunajitHi Gunajit
you need to ensure that the connections are properly closed. If you are
closing the connections properly, increase the number of connections in the
connection pool.
hth
sree
"Gunajit" <[email protected]> wrote in message
news:3ce082ca$[email protected]..
>
Hi,
I am having a strange problem accessing JDBC Driver ( for InformixDatabase, if this
information helps )
I am using Data Access Objects ( DAOs ) to fetch multiple records.
The DAO is accessed from Session Bean for this case.
The constructor of the DAO does the JNDI lookup for the TxDataSource
and set it to a class attribute of the DAO. This DataSource is pointing
to a connection pool
In the getConnection() private method if DAO we use this DataSource
to pickup a onnection from the pool and fire a sql query.
This public method say getMultipleRecords( query conditions ) of DAO
returns a number of macthing records to the Session Bean.
This approach works fine in general. But sometimes I get an
java.sql.SQLException
SQLException ERROR MESSAGE is:
"Error accessing jdbc driver: driverURL = jdbc:weblogic:pool:myConnPool,props= {enableTwoPhaseCommit=true,
connectionPoolID=myConnPool}"
Once this exception occurs every time the method is called the sameexception keep
coming.
Once I restart the server this API starts working again.
Could anyone give any reason why this exception might occur.
Please send an e-mail to [email protected] while replying to this
message.
>
Thanks in advance
Gunajit -
Managed Beans and Data Access Object
I have a question / need help understanding how to configure backing bean and model objects so that memory and object creation/deletion is done as efficiently as possible.
1. I have a .jsf page with a form and a commandbutton that submits the form inputs to a backing bean (enrollispbean is backing bean)
<h:commandButton value="Enter" action="#{enrollispbean.insert}"/>
2. The backing bean is used for form handling - the insert() method is used to read the data fields from the form and create a SQL string that will be submitted to a model object, DbInsert, that is used as a generic data access object that connects to the database and insert the SQL string:
public class EnrollIspBean {
private String beanvar1="";
private String beanvar2= "";
// DbInsert is data access object
private DbInsert dbinsert = new DbInsert();
public String insert (){
String sqlstmt;
sqlstmt = "INSERT INTO ispmain VALUES(beanvar1, beanvar2,..)"
dbinsert.insert(sqlstmt);
return "success"; }
3. DbInsert is the data access object that contains a method, insert(), that accepts a sql string to insert into the database. This method contains the code to obtain a connection from the database connection pool and then execute the sql statement (note: error checking code not shown):
public class DbInsert {
public void insert(String sqlstmt) throws SQLException {
Connection conn = null;
GetDBConnection getdbconnection = new GetDBConnection();
PreparedStatement stmt = null;
conn = getdbconnection.getdbconn();
stmt = conn.prepareStatement(sqlstmt);
stmt.executeUpdate();
stmt.close();
conn.close();
return;
Where I need help understanding is how to set up the scope for the managed beans and data access object. Currently, I have the backing bean within the session scope (using the facesconfig.xml file). My main question is how to set up the scope for the Data Access Object - currently I do not have it as a managed bean within facesconfig.xml. Instead I am creating a new instance within the backing bean:
private DbInsert dbinsert = new DbInsert();
Is this the best way to do this? Will the DBInsert object now be tied to the session scope of the backing bean (i.e., when backing bean is deleted, the DbInsert object will be deleted from session scope as well.)
Ideally I would like the data access object to be available as a shared object throughout the life of the application. When I was programming using a servlet approach, I would have created a servlet to load on startup. Now that I'm using java server faces, I'm confused about the scope / how to efficiently set up a data access object that I want to be available to all backing beans in the application.
tnanks for any help understanding this.
TomI was thinking about setting the data access object as application scope so that it can be used by an backing bean to execute sql statements.
If I do set it as application scope, however, if I do this, do I still need to declare a new instance of the object from within each bean that uses the object?
For example do I need to declare a new instance of the data access object from within the bean? or, should I assume that there is always an instance of the bean available in the application scope, and if so, how do I reference it from within the bean?
Bean Code:
public class EnrollIspBean {
// DbInsert is data access object
private DbInsert dbinsert = new DbInsert();
Finally, I understand performance may be an issue if I have one instance of the data access object available in the application scope - is there a way to make multiple instances available in the application scope?
thanks -
Using SequenceFactory getNext in persistent object constructor
Hi,
Rightly or wrongly (maybe wrongly cos I am getting problems...)
In my persistent object constructors, I am initialising the objects id
field using the sequence factory getNext() method.
If I run the schematool on a blank DB with no tables then it works fine -
classes are enhanced, tables created.
But if I run it again on the same db, it fails on the first persistent
object, with this stack trace:
[java] java.lang.ExceptionInInitializerError:
javax.jdo.JDOFatalUserException: The system could not initialize; the
following registered persistent types are missing metadata or have not
been enhanced: [class com.rabobank.reef.tradeadapters.dto.ReefSystem].
[java] at
com.solarmetric.kodo.impl.jdbc.JDBCPersistenceManagerFactory.loadPersistentTypes(JDBCPersistenceManagerFactory.java:293)
[java] at
com.solarmetric.kodo.impl.jdbc.JDBCPersistenceManagerFactory.setup(JDBCPersistenceManagerFactory.java:256)
[java] at
com.solarmetric.kodo.runtime.PersistenceManagerFactoryImpl.privateSetup(PersistenceManagerFactoryImpl.java:872)
[java] at
com.solarmetric.kodo.runtime.PersistenceManagerFactoryImpl.getConnectionFactory(PersistenceManagerFactoryImpl.java:223)
[java] at
com.solarmetric.kodo.impl.jdbc.JDBCPersistenceManagerFactory.setLogWriter(JDBCPersistenceManagerFactory.java:175)
[java] at com.rabobank.util.kodo.JDOFactory.<init>(Unknown Source)
[java] at com.rabobank.util.kodo.JDOFactory.getInstance(Unknown
Source)
[java] at
com.rabobank.util.kodo.JDOFactory.getNextPrimaryKey(Unknown Source)
[java] at
com.rabobank.reef.tradeadapters.dto.GenericObject.<init>(Unknown Source)
[java] at
com.rabobank.reef.tradeadapters.dto.ReefSystem.<init>(Unknown Source)
[java] at
com.rabobank.reef.tradeadapters.dto.ReefSystem.<clinit>(Unknown Source)
[java] at java.lang.Class.forName0(Native Method)
[java] at java.lang.Class.forName(Class.java:115)
[java] at
com.solarmetric.kodo.impl.jdbc.schema.SchemaTool.main(SchemaTool.java:1115)
[java] Exception in thread "main"
Which looks like the sequence factory requires an initialised system to be
accessed, but it is trying to init the system when it is called?
But it works on a clean db...
I am just going about this the wrong way or is it a simple bug in my
procedure?
Thanks,
Chrisheres the exact error message im getting
Exception in thread "main" java.lang.NullPointerException
at instrument.<init>(instrument.java:15)
at iContainer.populate(iContainer.java:34)
at main.main(main.java:7)
the bolded line is the erroneous one
public instrument(int newID, String newType, String newRenters [], int newPrice, String newKey, boolean newNeedsRepairs)
super(newID);
type = newType;
for ( int x = 0; x < newRenters.length; x++)
*renters[x] = newRenters[x];*
price = newPrice;
key = newKey;
needsRepairs = newNeedsRepairs;
} -
Post Author: aya
CA Forum: Crystal Reports
Hi I am getting following problem while launching Crystal Report
Failed to retrieve data from the database. Details: [Database Vendor Code: 997 ] Failed to retrieve data from the database. Details: [Database Vendor Code: 997 ]
The database is Oracle.
ThanksPost Author: pvierheilig
CA Forum: Crystal Reports
Have you been able to resolve this yet? I don't have any reference to Oracle error codes but would suspect a quick Google of something like 'Oracle error code 997' should result in good information, since it is an Oracle error...
Hope this helps. -
Hello,
I am trying to implement the Data Access Object pattern and I have the following bean:
package com.netpepper.ecards;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.faces.application.Action;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
* @author Julien Martin
* Card class: represents the card sent from a member of the public (the sender)
* to another member of the public (the recipient).
public class Card {
private static Log log = LogFactory.getLog(Card.class);
private long id;
private String from_email;
private String to_email;
private String image;
private String bgcolor;
private String font;
private String from_name;
private String to_name;
private String message;
private String title;
private boolean received;
private boolean sent;
private String send_date;
private String response;
* Public empty no-arg constructor
public Card() {}
* Full-fledged constructor
public Card(
long id,
String from_email,
String to_email,
String image,
String bgcolor,
String font,
String from_name,
String to_name,
String message,
String title,
boolean received,
boolean sent,
String send_date) {
setId(id);
setFrom_email(from_email);
setTo_email(to_email);
setImage(image);
setBgcolor(bgcolor);
setFont(font);
setFrom_name(from_name);
setTo_name(to_name);
setMessage(message);
setTitle(title);
setReceived(received);
setSent(sent);
setSend_date(send_date);
* @return the background color choosed by the sender.
public String getBgcolor() {
return bgcolor;
* @return the font choosed by the sender.
public String getFont() {
return font;
* @return the sender's email.
public String getFrom_email() {
return from_email;
* @return the sender's name.
public String getFrom_name() {
return from_name;
* @return the card's id.
public long getId() {
return id;
* @return the image choosed by the sender.
public String getImage() {
return image;
* @return the message input by the sender.
public String getMessage() {
return message;
* @return <code>true</code> if the card has been received, <code>false</code> otherwise.
public boolean isReceived() {
return received;
* @return <code>true</code> if the card has been sent, <code>false</code> otherwise.
public boolean isSent() {
return sent;
* @return the title choosed by the sender.
public String getTitle() {
return title;
* @return the recipient's email.
public String getTo_email() {
return to_email;
* @return the recipient's name.
public String getTo_name() {
return to_name;
* @param the background color choosed by the sender.
public void setBgcolor(String string) {
bgcolor = string;
* @param the font choosed by the sender.
public void setFont(String string) {
font = string;
* @param the sender's email.
public void setFrom_email(String string) {
from_email = string;
* @param the sender's name.
public void setFrom_name(String string) {
from_name = string;
* @param the card's id.
public void setId(long i) {
id = i;
* @param the image choosed by the sender.
public void setImage(String string) {
image = string;
* @param the message input by the sender.
public void setMessage(String string) {
message = string;
* @param <code>true</code> if the card has been received, <code>false</code> otherwise.
* If the application attempts to set the received field to true,
* then the received field of the Card object is persisted to database
* and an email is sent to the sender to notify them that the card has been received.
public void setReceived(boolean b) {
if (this.received == false && b == true) {
Mailer m = new Mailer();
try {
m.sendAcknowlegement(
to_email,
from_email,
from_name,
to_name,
id);
Connection con = DBConnection.getConnection();
PreparedStatement ps =
con.prepareStatement(Queries.setReceivedQuery);
ps.setLong(1, this.id);
ps.executeUpdate();
con.close();
this.received = true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
* @param <code>true</code> if the card has been sent, <code>false</code> otherwise.
* If the application attempts to set the send field to true,
* then the sent field of the Card object is persisted to database.
public void setSent(boolean b) {
if (this.sent == false && b == true) {
try {
Connection con = DBConnection.getConnection();
PreparedStatement ps =
con.prepareStatement(Queries.setSentQuery);
ps.setLong(1, this.id);
ps.executeUpdate();
con.close();
} catch (SQLException e) {
log.error("ERROR: impossible to update the sent field");
e.printStackTrace();
* @param the title choosed by the sender.
public void setTitle(String string) {
title = string;
* @param the recipient's email.
public void setTo_email(String string) {
to_email = string;
* @param the recipient's name.
public void setTo_name(String string) {
to_name = string;
* @return the send date.
public String getSend_date() {
return send_date;
* @param the send date.
public void setSend_date(String string) {
send_date = string;
* @return <code>true</code> if email has been sent, <code>false</code> otherwise.
public boolean sendEmail() {
try {
Mailer sm = new Mailer();
sm.sendCard(
this.from_email,
this.to_email,
this.from_name,
this.to_name,
this.id);
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
* Retrieve the card from the database
public static Card getCardFromId(int id) {
Card c = new Card();
c.id = id;
try {
Connection con = DBConnection.getConnection();
PreparedStatement ps = con.prepareStatement(Queries.getCardFromID);
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
c.setBgcolor(rs.getString("db_bgcolor"));
c.setFont(rs.getString("db_font"));
c.setFrom_email(rs.getString("db_from_email"));
c.setTo_email(rs.getString("db_to_email"));
c.setFrom_name(rs.getString("db_from_name"));
c.setTo_name(rs.getString("db_to_name"));
c.setFont(rs.getString("db_font"));
c.setMessage((String) rs.getObject("db_message"));
c.setTitle(rs.getString("db_title"));
c.setSend_date(rs.getString("db_send_date"));
c.setImage(rs.getString("db_image"));
if (rs.getString("db_received").equals("y")) {
c.received = true;
} else if (rs.getString("db_received").equals("n")) {
c.setReceived(true);
if (rs.getString("db_sent").equals("y")) {
c.setSent(true);
} else if (rs.getString("db_sent").equals("n")) {
c.setSent(false);
System.out.println(c);
//con.close();
return c;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
public String toString() {
return ("Title: " + this.title + ", " + "Id: " + this.id);
* @param string
public void setResponse(String string) {
response = string;
protected String saveCard() {
try {
Connection con = DBConnection.getConnection();
PreparedStatement ps = con.prepareStatement(Queries.saveCard);
ps.setLong(1, (new java.util.Date()).getTime());
ps.setString(2, this.from_email);
ps.setString(3, this.to_email);
ps.setString(4, this.image);
ps.setString(5, this.bgcolor);
ps.setString(6, this.font);
ps.setString(7, this.from_name);
ps.setString(8, this.to_name);
ps.setString(9, this.message);
ps.setString(10, this.title);
ps.setString(11, this.send_date);
ps.executeUpdate();
con.close();
return "saved";
} catch (SQLException e) {
log.error("ERROR: impossible to save the card");
e.printStackTrace();
return "notSaved";
public Action getSaveCard() {
return new Action() {
public String invoke() {
return saveCard();
}The full source code for the project can be downloaded here:
http://cours.java.free.fr/ecards-project/
I would like to decouple the bean from the jdbc but I don't know how to. Can anyone help please?
I found some sampes here http://access1.sun.com/codesamples/DataAccessObject.html
but it does not have any update jdbc.
Julien.Your DAO should have methods for getting and setting beans.
For example:
public Card getCard(long id){...}
public void updateCard(Card c) {...} -
Why database related code not wriiten in jsp's
hi all
what all resons are there for which database related code
is not written in jsp's
one thing that i know is
it's not a j2ee architecture to do so
so is it the thing that doing so hits the performance issue
thanxMe, I'm still trying to get my head around Java 1.5, J2EE, Tomcat, JBoss, and Oracle RAC (both programming and DBAing)... My head hurts... Badly...
Back to the topic, though... I also agree with the previous posters...
I agree there are exceptions to the "no JDBC in JSP rule of thumb"- I have a JSP-based generic table browser as a tool for emergency maintenance from a (presumably) hostile network, it provides read-only access and automatic password rotation. The flexibility of having it in the JSP has saved my bacon in a crisis; when travelling, I had to talk a non-programmer through applying a code fix (damn developers, using reserved words as column name...)( I had the source on my laptop...). To get a class file fixed, I would have had to get a programmer on the phone, and get the server to reload the class which in our environment at the time required an application restart... The project I work on is about 70 man-years of work, mostly Java, and we have maybe 6 or 8 JSPs that access the DB directly...
Most of the time though, good design says that you access a particular "type" of data (table or group of tables) in the same "chunk" of code, jsp or class file. It's a lot harder to share a jsp among different invokers than it is a class file. It's also better to isolate presentation from data access.
Imagine that you have a "USER" table, with first name, last name, username, and password. You program a "login" jsp, a user "edit" jsp and an administrator "edit" jsp. Then a security audit declares that saving an unexcrypted password in the database is insecure; you now have to change evey place that can access the password. If the user object was accessed through a single Java class file, then there would be only one place to fix. Of course, it's possible to use jsp includes to simulate class files, but that's just about as much work as creating the class file to begin with, with more problems.
Another big advantage of keeping your data access out of JSPs is that you can write unit tests much more easily for the Java classes, using something like JUnit. You can have a set of tests for all your persisted data, which can be run anytime your data model changes. This makes it a lot harder for "side effect" bugs to creep into your code. -
Data Access Object for Data Warehouse?
Hi,
Does anyone know how the DAO pattern looks like when it is used for a data warehouse rather than a normal transactional database?
Normally we have something like CustomerDAO or ProductDAO in the DAO pattern, but for data warehouse applications, JOINs are used and multiple tables are queried, for example, a query may contains data from the Customer, Product and Time table, what should the DAO class be named? CustomerProductTimeDAO?? Any difference in other parts of the pattern?
Thanks in advance.
SKIn my opinion, there are no differences in the Data Access Object design pattern which have any thing to do with any characteristic of its implementation or the storage format of the data the pattern is designed to function with.
The core pupose of the DAO design pattern is to encapsulate data access code and separate it from the business logic code of the application. A DAO implementation might vary from application to application. The design pattern does not specify any implementation details. A DAO implementation can be applied to group of XML data files, an Excel-based CSV file, a relational database, or an OS file system. The design is the same for all these, it is the implementation that varies.
The core difference between an operational database and a strategic data warehouse is the purpose of why and how the data is used. It is not so much a technical difference. The relational design may vary however, there may be more tables amd ternary relationships in a data warehouse to support more fine-tuned queries; there may be less tables in a operational database to support insert/add efficiencies.
The DAO implementation for a data warehouse would be based on the model of the databases. However the tables are set up, that is how the DAO is coded. -
Deepak,
Can you throw some light on the 'Data access Objects" pattern? and how it can be used with Entity beans? I am trying to apply this to the following scenario and having a hard time.
We need users to be transparent of the data retrieval from various sources like oracle database, flat files or legacy storage. If I use the data access object pattern it is easier to use java classes in place of entity beans.
Thanks
Shreyas KamatShreyas,
[For those not familiar with our Data Access Object Pattern, the
beta version of the pattern is available on JDC (needs JDC login) at:
http://developer.java.sun.com/developer/restricted/patterns/DataAccessObject.html]
Data Access Objects (or DAOs) are objects that hide the database
implementation from data clients. Data clients are any objects
that need to retrieve data from the data source. And the data source
could be anything that contains data, not necessarily only RDBMSs.
For example, an external system could be a data source.
Now using DAOs with Entity beans is applicable only in bean-managed
persistence (BMP) scenario. In BMP, the entity beans are responsible
to provide the data load and store implementation in the ejbLoad()
and ejbStore() methods of the bean implementation. Without using
the DAOs, the entity bean class will contain all the JDBC code (assuming
that the data source is an RDBMS), SQL, etc. This makes the
entity bean class bloated and difficult to manage when changes
are made to the data logic. In addition, this tightly couples the
data source implementation with the entity bean implementation.
By using DAOs, the ejbStore() and ejbLoad() methods are much
simpler. Also, it is easier to change from one datasource implementation
to another by replacing the DAOs. Further flexibility is possible
by employing the DAO factory strategy as described in the DAO pattern
in our catalog.
Coming back to you point about making the data access transparent
to the clients; it is possible to achieve this by using DAO and
DAO factory strategy. In the current version of the pattern,
included in the book, we provide sample code to show how
to design DAO classes and to apply DAO factory strategy.
On your last point about using java classes instead of entity beans, this
is not the intention of the DAO pattern. Entity beans serve a different
purpose in the architecture as coarse-grained transactional components.
entity beans use DAOs in BMP implementations, but are not replaced
by DAOs. However, DAO classes are reusable. The same DAO that is
used by an entity bean to retrieve some data in one application scenario,
can be reused by a servlet in another application scenario
that needs the same data, but does not use entity beans.
So bottom line is that DAOs address the need to data access and
manipulation and work together with entity beans in BMP implementations.
thanks,
-deepak -
Data Access Objects (Wizard)
Does SJSE 8 happen to have a wizard that allows you to use the database explorer and create Data Access Objects from tables? If not does anybody know of a good tool to do so. I will be working with IBM iSeries (DB2).
I worked on a JDO runtime a long time ago during JDO's infancy, so I'm personally biased towards it . I like it because it allows you to treat your data objects as normal java objects instead of heavy-weight objects such as CMP beans. As I remember, the JDO runtime I worked on used byte code enhancer to inject code into your byte code to keep track of changes made by plain assignment statements. (Not sure if it works that way for other implementations.)
You might want to check out the following link on SDN:
http://java.sun.com/products/jdo/
Also, there is FAQ on JDO vs. J2EE Persistence you should read before you make a decision:
http://java.sun.com/j2ee/persistence/faq.html
Good luck. -
Is there any way to access the superclass' superclass' constructor?
Hi,
Is there any way to access the superclass' superclass' constructor?
e.g.
class A {...}
class B extends A {...}
class C extends B {
public C() {
// can I do something like super.super();
// I mean then doesn't work, but is there anything similar?
}In the OP you don't need to call "super.super()" since the A class no-args constructor will be invoked anyway.
You can, however, invoke constructors using reflection. For example:
public class A {
public A() {
System.out.println("A()!");
public A(int i) {
System.out.println("A(int i)! : " + i);
public class B extends A {
public B() {
System.out.println("B()!");
public class C extends B {
public C() throws Exception {
Class types[] = new Class[1];
types[0] = Integer.TYPE;
Object args[] = new Object[1];
args[0] = new Integer(1);
this.getClass().getSuperclass().getSuperclass().getConstructor(types).newInstance(args);
System.out.println("C()!");
public static void main(String[] args) throws Exception {
new C();
}Will print:
A()!
B()!
A(int i)! : 1
C()!
btw: DON'T use this code! It's just to show you that it's possible. -
Failed to open the connection. Details: [Database Vendor Code: 53 ]
I'm upgrading one of our applications from Visual Studio 2005 to 2010. In the process I'm also switching our reports to run using Stored Procedures instead of Tables/Views. Everything runs fine on development machines after all the migration work. On the server however, it does not work. And I am getting the error message ""
Server is Windows 2003 Server 32 bit. And yes, I have installed the latest runtimes version 13.0.2000.0 on the server. There have been no other changes on the server other than to switch the target framework on the website in question from .net 2 to .net 4, and then to modify the web.config file to remove references to the older Crystal Reports and replace with references to the newer version.
I've seen many other threads on this "failed to open the connection" errors but none of them are my problem except there is one post that remains unanswered where someone had the same Database Vendor Code 53. I don't know what that error means, spent a considerable amount of time researching that before asking this question.
Lastly, it appears that this error only happens when the report is pulling data from a Stored Procedure rather than Tables/Views. If I re-copy the previous reports, they still work.
The ODBC drivers haven't changed, nor should they. They are fully up to date on that server machine.
I can't think of anything else that would be indicative of anything other than this is a bug. Here is the error text as it shows up in the event log:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 12/7/2011 3:49:50 PM
Event time (UTC): 12/7/2011 11:49:50 PM
Event ID: 38ce5b5487984e8aa8d2b84493d859a8
Event sequence: 17
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/739252194/Root-1-129677751941252500
Trust level: Full
Application Virtual Path: /
Application Path: D:\Websites\ACE5\Clients\TST\
Machine name: ACE1
Process information:
Process ID: 5436
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Exception information:
Exception type: InternalException
Exception message: Failed to open the connection.
Failed to open the connection.
Details: [Database Vendor Code: 53 ]
Failed to open the connection.
Details: [Database Vendor Code: 53 ]
Failed to open the connection.
PackSlipTST0 {638463B4-2196-492A-BD6E-9D82CB1862D5}.rpt
at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportOptions options, HttpResponse response, Boolean asAttachment, String attachmentName)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportFormatType formatType, HttpResponse response, Boolean asAttachment, String attachmentName)
at Distribution_PackingSlips_default.ExportPackingSlips(String CrystalReportPath, Boolean UseStoredProcedure)
at Distribution_PackingSlips_default.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Failed to open the connection.
Failed to open the connection.
Details: [Database Vendor Code: 53 ]
Failed to open the connection.
Details: [Database Vendor Code: 53 ]
Failed to open the connection.
PackSlipTST0 {638463B4-2196-492A-BD6E-9D82CB1862D5}.rpt
at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)Lots of great info here, except for the database; MS SQL? Oracle? Etc?
Database Vendor Code 53 is an error code that the CR engine simply passes straight from the database it's self. E.g.; look at your database error code and you should be able to find a verbose description of the error.
As a test, what happens if you add the report to your project and run it in the CR design part of the .NET IDE?
- A quick google search of Error 53 (for MS SQL - an assumption) comes up with a number of good hits. E.g.;
http://social.msdn.microsoft.com/Forums/en-AU/sqlgetstarted/thread/27684811-1a59-4273-b7ed-3cc990b4f20a
Ludek
Follow us on Twitter http://twitter.com/SAPCRNetSup
Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]
Edited by: Ludek Uher on Dec 8, 2011 6:31 AM -
Unable to connect: incorrect log on parameters. Database Vendor Code: 18456
I have imported a report into Info View (that has no parameters), I am able to run the report on Demand in InfoView, and I am also able to run the report within the CMC Preview. I have tried scheduling using the admin account in CMC, through the publishing wizard and also with a authorized users in InfoView. But anytime I try to schedule the report I get this error.
Status: Failed
Printer: The instance is not printed.
External Destination: Mail the instance to " XXX@XXX .com " with a subject of " test ".
Data Refresh Settings: Use the server defaults.
Start Time: 11/18/08 3:02:19 PM
End Time: 11/18/08 3:02:23 PM
Server Used: clr-combr.reportjobserver
Error Message: Error in File C:\Program Files\Business Objects\BusinessObjects Enterprise 11.5\Data\procSched\clr-combr.reportjobserver\~tmp1304574d76168ca.rpt: Unable to connect: incorrect log on parameters. Details: [Database Vendor Code: 18456 ]
I have made sure that the Reportjobobject is enabled and the server for SMTP email is enabled, and I am pretty sure I have the properties set up correctly within there, we created a email account specifically for crystal. And that email account is also set up as a user. I don't know where else to look.
Please help.
ThanksHi Ashley
I would like to suggest you following things with the Report:
1) Please log in into CMC, go to Report which you want to schedule.
2) Click on the report and go to Process
3) Click on the tab Database.
4) There will be two option to make the entries for database logon required for the Report.
Please select the appropriate option. Are you able to Preview the report?
What is the database in use? Please also check the odbc driver settings for that database. -
am sumanjali.i did a certification programme in database.i know my mc id and i don't know my access code.i want to download my certificate.please help me.
my mc id:10465528.
mail id:<redacted>
candidate id:8753634
site id:90043984
registration:<redacted>You'll need to contact the issuing body for your certification
I'm moving the thread to a forum where someone may be able to point you in the right direction.
Noel Paton | Nil Carborundum Illegitemi
CrashFixPC |
The Three-toed Sloth
No - I do not work for Microsoft, or any of its contractors. -
How to access complex data type objects in webdynpro
Hi
Need help on the detailed procedure to access the complex data type objects.
I am importing an external wsdl file, its request and response have complex data type objects , how do i access the same as the values are nested in them.
The structure of request and response at my end is as below:
request(I level)
--complextypeobject(II level)
requestheader(III level)
field1
field2
request
--response
messages
resp1
resp2
Any help would be highly appreciated.
Thanks and Regards,
Amar Bhagat Challa.here you go
WS Structure
Request_MI_PortWellOB_MI_PortWellOB
|-- MT_PortWellOut
|--agency ( attr)
|--user (attr)
|-- well ( node)
|-- borehole
|-- downhole
|-- interval
|-- surface
// code to set complex type
wdContext.nodeRequest_MI_PortWellOB_MI_PortWellOB().bind(new Request_MI_PortWellOB_MI_PortWellOB());
// port well object
Request_MI_PortWellOB_MI_PortWellOB oPWRequest = new Request_MI_PortWellOB_MI_PortWellOB();
ComplexType_DT_PortWell oPWParameters = new ComplexType_DT_PortWell();
oPWRequest.setMT_PortWellOut(oPWParameters);
wdContext.nodeRequest_MI_PortWellOB_MI_PortWellOB().bind(oPWRequest);
DT_PortWell oPWInputbean =
this.wdContext.nodeRequest_MI_PortWellOB_MI_PortWellOB().nodeMT_PortWellOut().currentMT_PortWellOutElement().modelObject().getOriginalBean();
// oPWInputbean.setTEST("test");
// well object
DT_CWR_Well oWParameters = new DT_CWR_Well();
// all object
// surface
DT_CWR_Surface oSParameters = new DT_CWR_Surface();
ComplexType_DT_CWR_Surface s = new ComplexType_DT_CWR_Surface();
// Borehole
DT_CWR_BoreHole[] oBParameters = new DT_CWR_BoreHole[wdContext.nodeBoreholedetail().size()];
// Downhole
DT_CWR_DownHole[] oDParameters = new DT_CWR_DownHole[wdContext.nodeDownholedetail().size()];
// Interval
DT_CWR_Interval[] oIParameters = new DT_CWR_Interval[wdContext.nodeIntervaldetail().size()];
// add all into well object
oWParameters.setSURFACE(oSParameters);
oWParameters.setBOREHOLE(oBParameters);
oWParameters.setDOWNHOLE(oDParameters);
oWParameters.setINTERVAL(oIParameters);
// oPWParameters.setWELL(oWParameters );
oPWInputbean.setWELL(oWParameters);
oPWRequest.setMT_PortWellOut(oPWParameters);
wdContext.nodeRequest_MI_PortWellOB_MI_PortWellOB().bind(oPWRequest);
wdContext.currentMT_PortWellOutElement().setUSERID("user");
wdContext.currentMT_PortWellOutElement().setAGENCY("agency");
Rahul
Maybe you are looking for
-
How can I highlight text in iPages with a 'virtual' fluorescent marker
How can I highlight text in iPages with a virtual fluorescent marker?
-
I have an application that I would like to map bc4j to a object type hierarchy in the database. From reading previous otn threads I'm under the impression that Domains are not used for Oracle Table Types, just for columns based on oracle types. The t
-
Hi friends, Can any one help me in this issue? I have created assignment cycle where the sender is a cost center and the receiver is different WBS elements and a cost center, I would like to know if there is any possibility that the val
-
While using linux I am getting the following message - "Your last session closed unexpectedly. You can restore the tabs and windows from the previous session, or start a new session if you think the problem was related to a page you were viewing". Wh
-
New forum area for Adobe Interactive forms
Would it be possible to create a separate thread for the adobe interactive forms? Most of the conversations are under the webdynpro forum, but because people refer to this area by so many different names (adobe, ADS, interactive forms) it is really