SV: [Shale] When to create a database Connection?

2006-03-29 Thread Hermod Opstvedt
Hi

Give me one good reason as to why you are doing this. If you let existing
tools do the job for you, you are going to relieve your self of a lot of
trouble. Have a look at Hibernate or equivalent, combined with Spring.

What you are doing here is really is something of the past.

Hermod


-Opprinnelig melding-
Fra: James Reynolds [mailto:[EMAIL PROTECTED] 
Sendt: 29. mars 2006 19:33
Til: Struts Users Mailing List
Emne: [Shale] When to create a database Connection?


I'm getting a null pointer error in my backing bean.  My grand plan was
to create a Connection in the init() method extended from the
AbstractViewController, so it can be used by any number of methods and
getters in my bean, and then close it in destroy().

In this simple case, the only place this Connection is used is in a
getter that returns a Result for a dataTable.  However, it doesn't seem
to be working as I get a null pointer exception.  If I move the
getConnection() method out of the init() method and into this getter,
then everything works great.

Am I miss-using the init() method?


Import lots.of.stuff;

public class Testimonial extends AbstractViewController {
private Connection conn = null;

public Testimonial(){
}

public void init() {
try {
conn = DbConnection.getConnection();
System.out.println();
} catch (SQLException e) {
e.printStackTrace();
}
}

public void destroy() {
try {
if (!conn.isClosed()) {
conn.close();
}
} catch (SQLException sqle) {
log(sqle.getMessage(), sqle);
sqle.printStackTrace();
}
}

public Result getAllTestimonials() {
/* ### moving the conn = DbConnection.getConnection() here
solves the problem ### */
Result result = null;
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(SqlStatements.ALL_TESITIMONIALS);
result = ResultSupport.toResult(ps.executeQuery());
} catch (SQLException sqle) {
System.out.println(SQL Exception: + sqle.getMessage());
sqle.printStackTrace();
} catch (Exception e) {
System.out.println(Exception: + e.getMessage());
e.printStackTrace();
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return result;
}
}


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



SV: [Shale] When to create a database Connection?

2006-03-29 Thread Hermod Opstvedt
Hi

We'll it all comes down to your skill set. There are plenty of online
tutorials, not to talk about printed matter, available. 

Since Spring relies on Dependency injection, and Hibernate on ORM, I guess a
basic to good OO background is desirable. However any fairly clever
programmer should be able to grasp this, at least at a basic level fairly
quick.

Hermod


-Opprinnelig melding-
Fra: James Reynolds [mailto:[EMAIL PROTECTED] 
Sendt: 29. mars 2006 21:16
Til: Struts Users Mailing List; [EMAIL PROTECTED]
Emne: RE: [Shale] When to create a database Connection?


Hi Hermod,

Here's my reason whineI'm under pressure to get this project complete
so I'm reluctant to take on learning Hibernate and Spring at this
time./whine  There's no question that would be a better way to do it,
but (as you can probably tell) I'm not an expert programmer.

Maybe my assumption is invalid, how challenging are these technologies
for new comers?

Thanks


-Original Message-
From: Hermod Opstvedt [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 29, 2006 11:45 AM
To: 'Struts Users Mailing List'
Subject: SV: [Shale] When to create a database Connection?

Hi

Give me one good reason as to why you are doing this. If you let
existing tools do the job for you, you are going to relieve your self of
a lot of trouble. Have a look at Hibernate or equivalent, combined with
Spring.

What you are doing here is really is something of the past.

Hermod


-Opprinnelig melding-
Fra: James Reynolds [mailto:[EMAIL PROTECTED]
Sendt: 29. mars 2006 19:33
Til: Struts Users Mailing List
Emne: [Shale] When to create a database Connection?


I'm getting a null pointer error in my backing bean.  My grand plan was
to create a Connection in the init() method extended from the
AbstractViewController, so it can be used by any number of methods and
getters in my bean, and then close it in destroy().

In this simple case, the only place this Connection is used is in a
getter that returns a Result for a dataTable.  However, it doesn't seem
to be working as I get a null pointer exception.  If I move the
getConnection() method out of the init() method and into this getter,
then everything works great.

Am I miss-using the init() method?


Import lots.of.stuff;

public class Testimonial extends AbstractViewController {
private Connection conn = null;

public Testimonial(){
}

public void init() {
try {
conn = DbConnection.getConnection();
System.out.println();
} catch (SQLException e) {
e.printStackTrace();
}
}

public void destroy() {
try {
if (!conn.isClosed()) {
conn.close();
}
} catch (SQLException sqle) {
log(sqle.getMessage(), sqle);
sqle.printStackTrace();
}
}

public Result getAllTestimonials() {
/* ### moving the conn = DbConnection.getConnection() here
solves the problem ### */
Result result = null;
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(SqlStatements.ALL_TESITIMONIALS);
result = ResultSupport.toResult(ps.executeQuery());
} catch (SQLException sqle) {
System.out.println(SQL Exception: + sqle.getMessage());
sqle.printStackTrace();
} catch (Exception e) {
System.out.println(Exception: + e.getMessage());
e.printStackTrace();
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return result;
}
}


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



SV: [Shale] When to create a database Connection?

2006-03-29 Thread Hermod Opstvedt
Hi

That's one of the equivalent I mentioned. Spring also supports it. iBatis
might be good if you are first and foremost an SQL guru, and not so much a
programmer with an OO background.

Med vennlig hilsen
Hermod Opstvedt
Webmaster
Seiling.org/Norlys.org


-Opprinnelig melding-
Fra: Yee, Richard K CTR DMDC [mailto:[EMAIL PROTECTED] 
Sendt: 29. mars 2006 22:34
Til: 'Struts Users Mailing List'
Emne: RE: [Shale] When to create a database Connection?

Check out iBATIS. You can use the DaoManager for a very lightweight
framework. It will handle getting and closing connections for you and also
handle transactions. With a little more configuration, you can use the
SqlMaps that will populate DTO objects for you.

-Richard


-Original Message-
From: James Reynolds [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 29, 2006 11:16 AM
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: RE: [Shale] When to create a database Connection?



Hi Hermod,

Here's my reason whineI'm under pressure to get this project complete so
I'm reluctant to take on learning Hibernate and Spring at this time./whine
There's no question that would be a better way to do it, but (as you can
probably tell) I'm not an expert programmer.

Maybe my assumption is invalid, how challenging are these technologies for
new comers?

Thanks


-Original Message-
From: Hermod Opstvedt [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 29, 2006 11:45 AM
To: 'Struts Users Mailing List'
Subject: SV: [Shale] When to create a database Connection?

Hi

Give me one good reason as to why you are doing this. If you let existing
tools do the job for you, you are going to relieve your self of a lot of
trouble. Have a look at Hibernate or equivalent, combined with Spring.

What you are doing here is really is something of the past.

Hermod


-Opprinnelig melding-
Fra: James Reynolds [mailto:[EMAIL PROTECTED]
Sendt: 29. mars 2006 19:33
Til: Struts Users Mailing List
Emne: [Shale] When to create a database Connection?


I'm getting a null pointer error in my backing bean.  My grand plan was to
create a Connection in the init() method extended from the
AbstractViewController, so it can be used by any number of methods and
getters in my bean, and then close it in destroy().

In this simple case, the only place this Connection is used is in a getter
that returns a Result for a dataTable.  However, it doesn't seem to be
working as I get a null pointer exception.  If I move the
getConnection() method out of the init() method and into this getter, then
everything works great.

Am I miss-using the init() method?


Import lots.of.stuff;

public class Testimonial extends AbstractViewController {
private Connection conn = null;

public Testimonial(){
}

public void init() {
try {
conn = DbConnection.getConnection();
System.out.println();
} catch (SQLException e) {
e.printStackTrace();
}
}

public void destroy() {
try {
if (!conn.isClosed()) {
conn.close();
}
} catch (SQLException sqle) {
log(sqle.getMessage(), sqle);
sqle.printStackTrace();
}
}

public Result getAllTestimonials() {
/* ### moving the conn = DbConnection.getConnection() here solves
the problem ### */
Result result = null;
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(SqlStatements.ALL_TESITIMONIALS);
result = ResultSupport.toResult(ps.executeQuery());
} catch (SQLException sqle) {
System.out.println(SQL Exception: + sqle.getMessage());
sqle.printStackTrace();
} catch (Exception e) {
System.out.println(Exception: + e.getMessage());
e.printStackTrace();
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return result;
}
}


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]