Win a copy of Rust Web Development this week in the Other Languages forum!

Yong Bakos

Greenhorn
+ Follow
since Jul 18, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Yong Bakos

Here's the big issue: the illustration on page 483 where the server "switches" ports is incorrect. See http://stackoverflow.com/questions/4307549/serversocket-accept-method?rq=1
I've got the answer. Note the two methods Socket#getPort and Socket#getLocalPort.
Below, see the chat client and server from pages 481 and 484 (HF Java 2nd Ed, chapter 15) where I've added some printing of port numbers.

Run the server, and run the client. If you run the client multiple times, you'll see the "local socket port" change, as it should per TCP's behavior.

But given the output, it seems like the socket is connected FROM 57xxx on the client TO port 4242 on the server, which still doesn't coincide with the explanation in the book (and other online examples) where the server seems to use a different port.

Anyone care to enlighten me?



I too would love to hear a response to this question.
If you're on windows and you've Java installed somewhere in a directory with a [space] in it (eg C:\program files\java), you'll probably have this problem.

SOLUTION:
unistall java
reinstall java in something like c:\java

I am soooo bummmmed...
Am I the only one still frustrated that Sun's been touting disconnected resultsets (RowSets) for years but they still don't work properly?
I've hear all sorts of workarounds to the NPE caused by instantiating a new *RowSetImpl() but what's the real issue?

And if the marketing copy states "included in Java 5" why the hell didn't they put it in javax.sql.rowset and document it in the API javadoc?

Frustrated....
The question I'm really asking is.
Why doesn't the API documentation for JDK 1.5 contain the *Impl implementations of all the RowSet interfaces?

Yuck!
Am I crazy, or does Java 5 _NOT_ include implementations of JDBC RowSets? I'm looking at the API doc and I only see interfaces. For example, I don't see CachedRowSetImpl here in my api doc (yes, I'm looking at javax.sql.*).

Which version of the JDBC spec does JDK 1.5 comply with? I thought that Sun would be including the old Rowset reference implementations with Java 5.
Hi Sejal, this probably varies a little according to what Servlet container you're using. But in general, you'll probably want to get a certificate and configure your app server accordingly. This will let you use https.

As for security constraints and other stuff, just follow the standard (declaring security constraints and such in your servlet container's config file)
16 years ago
You might want to try asking your question on the Resin group mailing list.
www.caucho.com
16 years ago
Sorry, a little better formatting...

16 years ago
For example.

public class AppData {

private final static DATA = new AppData();
private final static CNSTRING = "jdbc:xsql://hostname/user/pass/etc";
private DataSource datasource;

public AppData getInstance() {
return DATA;
}

private AppData() {
if (datasource == null) {
try {
// try to get a reference to the datasource via the servlet
// container's provided jndi name
Context env = (Context)new InitialContext().lookup("java:comp/env");
datasource = (DataSource)env.lookup("jdbc/mydatabase");
} catch (NamingException e) {
// handle it
}
}
}

private Connection getConnection() {
Connection cn = null;
if (datasource = null) {
// (If the datasource is null, the jndi lookup probably failed. So try
// loading the driver and getting a connection from DriverManager
try {
Class.forName("sun.jdbc.MyDatabaseJdbcDriver");
cn = DriverManager.getConnection(CNSTRING);
} catch (Exception e) {
// handle it
}
} else {
// ...otherwise just get a connection from the DataSource
try {
cn = datasource.getConnection();
} catch (Exception e) {
// handle it
}
}
return cn;
}

}

Is there a better way to handle this?

In addition, do you know if a DriverManager is actually provided by the container as well? For example, using the jndi lookup to get a datasource gives me a nice pooled datasource class provided by my servlet container, whose getConnection() method gives me a nice pooled connection. Do I only get database pooling when getting connections from a DataSource, or do I also get them via DriverManager.getConnection()?
16 years ago
In my webapp I'd like to encapsulate database access in a single class, say AppData, that classes in the model can use to populate their own fields. In addition, this would allow me to test the model classes on their own, isolated from the rest of the application.

But how would you handle database access in the AppData class to do this? For example, from within my servlet container the <database> declaration makes the datasource available to my application. But from outside the container, I have to load the driver manually with Class.forName() and use the DriverManager to get a Connection.

Is this just a tradeoff I'd have to live with? Seems there should be A Better Way...
16 years ago
[whoops. continued...]

previous user request. For example, if the tag first renders

<select name="preference">
<option></option>
<option>Ale</option>
<option>Amber</option>
</select>

And the user selects "Ale," what do you do with that data in the request so that the custom tag can render

<select name="preference">
<option></option>
<option SELECTED>Ale</option>
<option>Amber</option>
</select>

in the jsp that handles the response?

Do you set a session-scoped variable, a request-scoped variable?
If you have a lot of these in a jsp, do you use an object to hold this data?

Cheers,
16 years ago
JSP
Was wondering if anyone would like to discuss their approach in maintaining mvc separation and how you handle some nice dynamic features in the view that are dependent on model data.

Let's say your JSP contains a custom tag that renders a select-list. The select-list defaults to a certain item depending on the previous (for one <option> in the list, one is rendered as <option selected> .
16 years ago
JSP
Ah, Template Method. My actual implementation is a little more complex so I'm sticking to this pattern, but you're right, I could probably gain some simplicity by just using a constructor argument that is unique for each child.

Danke, Ilja!
16 years ago