> Hi,
>
> Does anyone know an example showing how to pass a database variable to
> a public variable??
One question mark would suffice.
> I would like to run a java file or JSP, passing <%= rs.getInt(1)%> to
> a servlet???
A JSP is a servlet, so you've already done that. What do you need the value for?
> The servlet would store the data, which could be retrieved using
> getAttribute.
Do you mean in a request attribute? Where do you intend to store the data?
You can set request attributes with the request setAttribute() method. Check
out the Javadocs.
> <%
Do not put Java in JSPs. It's legal, but foolish.
> String connectionUrl =("jdbc:jtds:sqlserver://localhost:1032/");
> String dbName="Calibration";
[quoted text clipped - 4 lines]
> // Establish the connection.
> Class.forName(driver).newInstance();
You don't need to load the DB driver class again and again, and you certainly
don't need to create a throwaway instance of it.
> con = DriverManager.getConnection(connectionUrl
> +dbName,user,password);
What if this fails? You have no Exception handling at all.
> stmt = con.createStatement() ;
> rs = stmt.executeQuery(querySQL) ;
From where do you get the query?
> ResultSetMetaData rsmd = rs.getMetaData() ;
You assign the value then never refer to it again except to drive an empty
loop. Why?
> for(int i = 1 ; i <= rsmd.getColumnCount() ; i++) {
> %>
Empty loop.
> <% } %>
>
> </tr>
Where's the opening <tr> tag? The enclosing <table>?
> <% while(rs.next()) { %>
> <tr>
[quoted text clipped - 6 lines]
> con.close();
> con = null;
What in the world do you expect to accomplish with setting con to null? It
goes out of scope anyway, so it's a useless action.
> %>
There are tags in the JSTL for SQL access that likely would be much easier for
you. JSPs should do their action through separate server-side classes or tag
libs so that all this Java scriptlet doesn't cruft up your presentation artifacts.
You've already got the value in a servlet, so I am not clear what else you
need to accomplish.

Signature
Lew
Clive_ - 13 Nov 2007 09:50 GMT
Hi Lew,
All my web development, etc was done using VB, eVB & Javascript.
In VB
Private Sub Test_Click()
'Declare variables
Dim i As Integer
Dim X As Integer
Dim Y As Integer
Dim ColumnNames As String
Dim ColumnValues As String
'Code to Auto Increment the Primary Key
Dim AutoNumber As Integer
Dim Identity As ADOCE.Recordset
Set Identity = CreateObject("ADOCE.Recordset.3.0")
Identity.Open "SELECT SiteID FROM HealthInspForm ORDER BY SiteID
DESC", CN
AutoNumber = CInt(Identity(0)) + 1
Identity.Close
'check to see if there's any editing in progress
If RS.EditMode <> adEditNone Then
MsgBox "There's editing in progress. Try the operation again
later."
Exit Sub
End If
SiteName = Var2
X = Var19
Y = Var20
'Add the new record
RS.AddNew
RS("SiteName") = SiteName
RS("Easting") = X
RS("Northing") = Y
'Ask user if they want the record added
If MsgBox("Do you wish to add this record?", vbYesNoCancel) =
vbYes Then
RS.Update
Else
RS.CancelUpdate
MsgBox "No new record added."
End If
'Query the database again to refresh the grid
RS.Requery
'Remove existing data from grid
For i = 1 To GridCtrl1.Rows
GridCtrl1.RemoveItem 0
Next
'Set the Grid columns equal to the field count
GridCtrl1.Cols = RS.Fields.Count
'Get the column names
For i = 0 To RS.Fields.Count - 1
ColumnNames = ColumnNames & RS.Fields(i).name & vbTab
Next
'Add the column headers to the grid
GridCtrl1.AddItem ColumnNames
'Loop through the recordset
While Not RS.EOF
'Get the column values for this row
For i = 0 To RS.Fields.Count - 1
ColumnValues = ColumnValues & RS.Fields(i).Value & vbTab
Next
'Add the column values to the row
GridCtrl1.AddItem ColumnValues
'Set ColumnValues to a zero length string
'so it can be refilled with the next row
ColumnValues = ""
RS.MoveNext
Wend
End Sub
I am new to Java and would like to find a simple example that shows/
explains the process. There are hundreds of VB examples that explain
the basics. I have not found a simple working example for JSP +
servlets. Once I have a working example then it is easier to
understand the javadocs.
Thanks
clive
Lew - 13 Nov 2007 13:37 GMT
> All my web development, etc was done using VB, eVB & Javascript.
>
[quoted text clipped - 3 lines]
> servlets. Once I have a working example then it is easier to
> understand the javadocs.
<http://java.sun.com/javaee/5/docs/tutorial/doc/>
The Sun tutorials are usually first place to look.
Marty Hall's books on Web development with Java are worthwhile also.
<http://www.coreservlets.com/>

Signature
Lew
Chris ( Val ) - 13 Nov 2007 14:00 GMT
> > All my web development, etc was done using VB, eVB & Javascript.
>
[quoted text clipped - 7 lines]
>
> The Sun tutorials are usually first place to look.
Yes, it is a good place to start.
> Marty Hall's books on Web development with Java are worthwhile also.
> <http://www.coreservlets.com/>
Yes - I like his book a lot, as it is very good
for a beginner to intermediate level.
I have been slowly working my way through his
tutorials, and I'm waiting for volume 2 of his book.
--
Chris