|
Home > Archive > WebSphere Portal Server > July 2007 > Portlet Question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I'm new to Java and even newer to WebSphere so please pardon my newbiness. Is it <i>wrong</i> to call a datasource you've created in WAS directly from a portlet?
Also, in this following snippet of code what does "comp" and "env" represent in the string?
<code>
Context initialContext = new InitialContext();
javax.sql.DataSource myDS =
(javax.sql.DataSource) initialContext.lookup(
"java:comp/env/jdbc/DB2DataSource");
// create a connection from the Data Source
Connection connection = myDS.getConnection();
// create a query from the connection
java.sql.Statement query =
connection.createStatement();
<code>
Thanks for reading.
| |
| Jessica Garcia-Glennie 2007-07-31, 1:21 pm |
| It's not wrong per se, but it's a lot more common to separate JDBC code into another layer that sits behind your portlet. Do you know much about persistence or the MVC pattern? This tutorial has my bible for a loooong time:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
The sun site also has a good tutorial on JDBC, but what you use as a jndi name (that string with /comp/env) is arbitrary. As for WAS, there is an infocenter, just like there is in Portal, and this link has a "How Do I?" section which includes "How do I p
rovide access to relational databases (JDBC resources) with the console?"
http://publib.boulder.ibm.com/infoc...owdoi_tadm.html
Good luck,
Jaye
| |
|
| Thank you so much - you rock! 
| |
| Jessica Garcia-Glennie 2007-07-31, 1:21 pm |
| teehee Excellent, thanks - a lovely compliment, even if it is from a Gator.
Jaye "Nole" Garcia-Glennie
|
|
|
|
|