Jeff Sunder

Ranch Hand
+ Follow
since Jun 26, 2001
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
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Jeff Sunder

You can put your results in a vector, then loop through your vector to display the results.
16 years ago
I am writing an application that connects to a database. I run a select sql statement that joins two tables and I am trying to put the sql results into variables. But I am unable to, the values of the variables is always null. But when I try a simple select statment without a join, it works fine. Is there something that I am missing ? Why does it not work when I join the two tables. In my code, I have ResultSet rs = stmt.executeQuesty(sql); Do I have to use a different method of the statement object ? Any help is appreciated.
16 years ago
I think the problem is comng from the while loop, when I'm looping through the resultset. What I am trying to do is capture all of the data in a 2 dimension array. One dimension the rows the other dimension the columns. When I comment out the line of code where the array is getting assinged, it works. But I have tried to redo the while statement, but still I am not able to get it to work. Does any one have any ideas?
Thanks in advance.
16 years ago
You need to check the http headers to determine the browser type. Here is a little script that works for me
<%
//determine browser type
if (request.getHeader("USER-AGENT").indexOf("MSIE") >= 0) {
//Your code here
}else{
//Your code here
}
%>
16 years ago
I have an application where I have a servlet connect to a db and perform sql commands, put the sql results in a multidimensional array, and then pass the multidimensional array to a jsp page to display. However, when I try to do this, something is going wrong, but I'm not sure what it is because I'm not getting any kind of error message. I have pinpointed to where the error is occuring and its when I try to set the values of the array, at this line:
resultsArray[v][s] = rs2.getString(s+1);
Here is the servlet:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class ProjectDetailProcess3 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
ConnectionPool connPool = null;
public void init(ServletConfig config) throws ServletException {
super.init(config);
String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String dbURL = "jdbc dbc:ProjectsDb";
try {
connPool = new ConnectionPool(jdbcDriver, dbURL, "projects", "projects");
connPool.setInitialConnections(5);
connPool.setIncrementalConnections(5);
connPool.setMaxConnections(15);
connPool.setTestTable("Projects");
connPool.createPool();
}catch (Exception e) {
System.out.println("Error " +e);
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String securityAccess = request.getParameter("pmsn");
int projectId = Integer.parseInt(request.getParameter("project"));
int projectDetailId = Integer.parseInt(request.getParameter("projDetail"));
Connection dbConn = null;
try{
dbConn = connPool.getConnection();
Statement stmt = dbConn.createStatement();
int numberOfRows = 0;
String getRowCount = "Select count(*) from projects";
ResultSet rs = stmt.executeQuery(getRowCount);
while (rs.next()) {
numberOfRows = Integer.parseInt(rs.getString(1));
}
rs.close();
String getDetails1 = "Select * from projects_detail";
ResultSet rs2 = stmt.executeQuery(getDetails1);
int numberOfColumns = rs2.getMetaData().getColumnCount();
//out.println("#"+numberOfColumns);
String[][] resultsArray = new String[numberOfRows][numberOfColumns];
while (rs2.next()) {
for (int v=0; v<=numberOfRows-1;v++) {
for (int s=0;s<=numberOfColumns-1;s++) {
resultsArray[v][s] = rs2.getString(s+1);
}
}
}
HttpSession session = request.getSession();
request.setAttribute("array", resultsArray);
try{
RequestDispatcher d = request.getRequestDispatcher("/jsp/Test.jsp");
d.include(request, response);
}catch (ServletException sx) {
}
}catch (Exception e) {
//out.println(e.getMessage());
}finally{
connPool.returnConnection(dbConn);
}
}
public void destroy() {
}
}
16 years ago
Is it possible to get the number of rows in a recordset ?
It seems like this is an easy question, but I have not been able to find any documentation that would help.
You need to implement a third party application to have jsp pages served on IIS. IIS is just a web server and cannot support jsp or servlets. You need to get a hold of JRun or Resin or Tomcat or any other third party tool.
I am not too clear about your second question. Are you looking for a chat application that will work on unix? If so, yahoo has a version of its messenger for the unix platform.
16 years ago
I like JBuilder because its all inclusive. You can create servlets, jsp pages, ejbs and anything else you can think of. You can code, compile, and even run your program within JBuilder (it has tomcat built in). It will also list possible methods when you identify a class.
16 years ago
Another method you can try is to create a unique number every time the form is loaded. The first time the page is submitted capture the number. If subsequent requests have the same unique #, discard that request. Once the processing of the servlet is over, discard the unique number. Hope that helps
16 years ago
I tried to do something similiar to this a whila back, but I got a IllegalStateException error every time. I think the problem is that the data must be transferred from the servlet to the jsp before the jsp's buffer is written. Something you might want to try is to put the html from the servlet into a variable and do the include as one of the first things in the JSP before the buffer is written. Let me know if this works or what solution you come up with, I am interested in how this would work.
[This message has been edited by Jeff Sunder (edited August 08, 2001).]
16 years ago
I am writing this jsp and I am getting an error stating:

Error: The variable "projName" may be accessed here before having been definitely assigned a value.


I don't understand why I am getting this error. Can any one shed some light on this? Here is the code:
<%@ page import="java.sql.*"%>
<%
ConnectionPool connPool = null;
String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String dbURL = "jdbc dbc:ProjectsDb";
int rowCount = 1;
try {
connPool = new ConnectionPool(jdbcDriver, dbURL, "projects", "projects");
connPool.setInitialConnections(5);
connPool.setIncrementalConnections(5);
connPool.setMaxConnections(15);
connPool.setTestTable("Projects");
connPool.createPool();
}catch (Exception e) {
System.out.println("Error " +e);
}

%>
<html>
<head>
<title>Project Updates</title>
<link rel="stylesheet" type="text/css" href="../css/newProject_input.css">
</head>
<body alink="blue" vlink="blue">
<table width="100%">
<%
String projId = request.getParameter("project");
String projName, projReason, projStatus, projStartDate, projEndDate, projPMFirst;
try{
Connection dbConn = null;
dbConn = connPool.getConnection();
Statement stmt = dbConn.createStatement();
String getAllProjects = "Select * From projects Where projects_id = " + projId;
ResultSet rs = stmt.executeQuery(getAllProjects);
out.println(getAllProjects);
while (rs.next()) {
/*out.println("<tr><td align=\"middle\">"+rowCount+".</td><td><a href=\"ProjectAdj.jsp?project="+rs.getString("projects_id")+"\">"+rs.getString("project_name")+"</a></td><td>"+rs.getString("project_reason")+"</td><t d align=\"middle\">"+rs.getString("status")+"</td>"+
"<td>"+rs.getString("submitter_first_name")+" "+rs.getString("submitter_last_name")+"</td>"+
"<td>"+rs.getString("department")+"</td><td>"+rs.getString("pl_first_name")+" "+rs.getString("pl_last_name")+"</td></tr>");
rowCount++;*/
projName = rs.getString("project_name");
projReason = rs.getString("project_reason");
projStatus = rs.getString("status");
projStartDate = rs.getString("start_date");
projEndDate = rs.getString("projected_end_date");
projPMFirst = rs.getString("pm_first_name");
out.print(projName+projReason);
}
}catch (Exception e) {
out.println(e.getMessage());
}
%>
<tr>
<td><input type="text" name="project_name" size="20" value="<%=projName%>"></td>
</tr>
</table>
</body>
</html>
I also ran into an error when I tried to assign the db results into the String variables outside of the while statement. The error was

[Microsoft][ODBC Driver Manager] Invalid cursor state

.
[This message has been edited by Jeff Sunder (edited August 07, 2001).]
16 years ago
Outputting the buttons within the servlet is same as outputting any other html code within a servlet. Use the out.print or out.println to output your html code. So you would have something like:
out.print("<input type=\"button\" name=\"button1\">");
I thought of one way to capture the button click, but have never tried it myself. But here it is anyways: using javascript, call a function that takes one parameter. the parameter will indicate which button is pressed, from there you can call a servlet depending on the button clicked. Here's an example,
<script language="JavaScript">
function sendToServlet(buttonPressed) {
if (buttonPressed == 1) {
window.location = "servlet/Add";
}else if (buttonPressed == 2) {
window.location = "servlet/Delete";
}else if (buttonPressed == 3) {
window.location = "servlet/Update";
}
</script>
In your servlet you will have:
out.println("<input type=\"button\" name=\"add\" Value=\"Add\" onClick=\"sendToServlet(1)\">");
Let me know if this works.
16 years ago
You need to set up a connection pool. A connection pool will allow for multiple simultaneous users to access your db. This will also reduce the overhead because it recycles connections rather than create new connections for every new user. Look at the CoonectionPool class to get started.
16 years ago
I have done a lot of research on this and the basic answer is that you cannot. There are many tricks that you can try, but none of them actually disable the back button.
You need to go the your server.xml file found under the tomcat/conf and change the reloadable attribute of the context tag to true for your particular application. If reloadable is not in the context element add the following as an attribute reloadable="true" .
16 years ago