Marl Atkins wrote:
Hi:
I'm admittedly worried about this one.
I'm running a simple SQL Statement: Select * From Profiles ORDER BY FName,
LName
If I run it from within a Java Main proc I get 2 records which is correct.
If I run it from a Browser/Applet through Javascript, I get NO errors but I
get 0 records.
I'm calling exactly the same proc in both cases.
I got the browser to print the sql statement and it's correct.
The amount of code total is a pretty good bit because of all the work I have
to do to move data in and out of Java to Javascript. The Jar is almost 3
megs. I can attach it if you like.
This prints in the browser (I display Globals.sDebug in DHtml):
ALERT In Do SearchGetting Row From String:
Got Row From String
Started Search
Select * From Profiles ORDER BY LName, FName
Executed Query
Got0
Got: 0
>From the main proc I do System.out.println(Globals.sDebug) and get:
In Do SearchGetting Row From String: <br>Got Row From String<br>Started
Search<br>Select * From Profiles ORDER BY LName, FName<BR>Executed
Query<BR>Got2<BR><BR>Got: 2<BR>
Any ideas as to why it works from a Java App and not from an Applet?
Here's the proc that does the call:
public DataTable getFilteredRecords(DataRow oFilter) throws Exception
{
ResultSet rs;
DataTable dtRecs;
StringBuffer sbSql = new StringBuffer();
try
{
sbSql.append("Select * From Profiles");
sbSql.append(buildFilter(oFilter));
sbSql.append(" ORDER BY LName, FName");
Globals.sDebug = sbSql.toString() + "<BR>"; //<<-- This shows
up in the browser
oCn = Globals.getCliCn();
CliStmt oStmt = new CliStmt();
rs = oStmt.executeQuery(oCn, sbSql.toString());
Globals.sDebug = "Executed Query<BR>"; //<<-- This shows up
in the browser
dtRecs = new DataTable(rs);
Globals.sDebug = "Got" + dtRecs.Rows.length + "<BR>"; //<<--
This shows up in the browser as 0
oStmt.close();
return dtRecs;
}
catch(Exception exp)
{
throw new Exception("Error in daProfile.getAllRecords:" +
exp.getMessage());
}
}
Here's the actual statement execution:
public ResultSet executeQuery(Connection oCn, String sql) throws Exception
{
stmt = null;
final String strSql = sql;
sErr = "";
try
{
final Statement stmt =
oCn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = (ResultSet)AccessController.doPrivileged(new
PrivilegedAction() {
public Object run()
{
try
{
return stmt.executeQuery(strSql);
}
catch(Exception exp)
{
sErr = exp.getMessage();
return null;
}
}
});
if(sErr != "")
{
throw (new Exception("Error in CliStmt.executeQuery:<br>" +
sql + "<br>" + sErr));
}
return rs;
}
catch (Exception exp)
{
throw (new Exception("Error in CliStmt.executeQuery:\r\n" +
sql + "\r\n" + exp.getMessage()));
}
}
Marl K. Atkins
Microsoft Certified Professional
SoftLink Systems, Inc.
(407) 388-1886
I don't have experience with Applets but have spoken to others who have
switched for using Applets to using Servlets because of the complexities
of establishing a connection from an applet. Are you using network
server or Derby embedded? By default applets do not have sufficient
privileges to start Derby and load a database (file creation issues
among others). Also locating the database can be difficult from an
applet.
I recommend activating some Derby debug properties and running the
Applet then checking the derby.log file to see if a connection is being
established and the proper SQL received. The following write-ups on the
WIKI cover some basic debug properties and logStatementText:
http://wiki.apache.org/db-derby/DebugPropertiesTmpl
http://wiki.apache.org/db-derby/LogStamentTextMsgs
HTH