aspose file tools*
The moose likes JDBC and the fly likes Updated: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Updated: "Invalid character constant", Help needed" Watch "Updated: "Invalid character constant", Help needed" New topic
Author

Updated: "Invalid character constant", Help needed

John Piper
Greenhorn

Joined: Mar 27, 2011
Posts: 12
I've seen several examples how how to pull columns and rows using Resultset but I'm trying to sum a single column and cannot figure out the last part where I display the result of the sum.

Here is the part of my code that executes the query:



Then further down in the code I want to pull that result and place it where the following placeholder is <%***%>



I've tried several things and I am getting no where. Any help is greatly appreciated.


Updated: Changed my code and have a new issue
John Piper wrote:I've changed my code quite a bit and am now getting the following error in NetBeans:

unclosed character literal

not a statement

unclosed character literal


And this message on Apache when trying to compile:


org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 26 in the jsp file: /categories.jsp
Invalid character constant
23: <body>
24: <table border='5'>
25: <jsp:useBean id="StockBean" class="HWpackage.StockBean" scope="request">
26: <jsp:setProperty name="StockBean" property="totalcost" value="<%=request.getAttribute('StockBean')%>" />
27: </jsp:useBean>
28: <tr>
29: <th>Welcome <%UserBean currentUser = (UserBean) (session.getAttribute("currentSessionUser"));%><%= currentUser.getUsername()%></th>


I'm officially about to start pulling out my hair.

I know it has to do with this part on line 26:



I did have it like this originally and NetBeans liked it but Apache did not:



I figured out it had to do with the double quotes within double quotes which as to do with new vs old way of coding on Apache. But I just can't figure out how to correct it in a way that will allow the code to compile.

Thanks for the help everyone.



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

So far you have the ResultSet. It has one row and one column which contains the number you wanted. So the missing code is the code which would read that row and extract that column.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

ResultSet has two ways of retrieving data from the current record - using the column name and using the column index. Since you haven't given your sum column a name (using the "AS" keyword) that leaves you the column index to retrieve the value.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
You need to write resultSet.get(1) or change the quey like

String QueryString = "SELECT sum(cost) as sum from stocks where username = 'currentUser.getUsername()'";

ResultSet costtotal = statement.executeQuery(QueryString);

Iterate the result set and get below value.
double x = costtoal.get("sum");

Hope this will solve your issue.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Almost right - there is no get(int) method in ResultSet. One of the type-specific methods is needed, like getString(int). That's not the right one though, because the result of the sum is not a String.
John Piper
Greenhorn

Joined: Mar 27, 2011
Posts: 12
I've changed my code quite a bit and am now getting the following error in NetBeans:

unclosed character literal

not a statement

unclosed character literal


And this message on Apache when trying to compile:


org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 26 in the jsp file: /categories.jsp
Invalid character constant
23: <body>
24: <table border='5'>
25: <jsp:useBean id="StockBean" class="HWpackage.StockBean" scope="request">
26: <jsp:setProperty name="StockBean" property="totalcost" value="<%=request.getAttribute('StockBean')%>" />
27: </jsp:useBean>
28: <tr>
29: <th>Welcome <%UserBean currentUser = (UserBean) (session.getAttribute("currentSessionUser"));%><%= currentUser.getUsername()%></th>


I'm officially about to start pulling out my hair.

I know it has to do with this part on line 26:



I did have it like this originally and NetBeans liked it but Apache did not:



I figured out it had to do with the double quotes within double quotes which as to do with new vs old way of coding on Apache. But I just can't figure out how to correct it in a way that will allow the code to compile.

Thanks for the help everyone.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

John Piper wrote:And this message on Apache when trying to compile:

I'm sure that you mean Tomcat. When people use just "Apache" it means the Apache Web Server, which has nothing to do with Java or JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Piper
Greenhorn

Joined: Mar 27, 2011
Posts: 12
Bear Bibeault wrote:
John Piper wrote:And this message on Apache when trying to compile:

I'm sure that you mean Tomcat. When people use just "Apache" it means the Apache Web Server, which has nothing to do with Java or JSP.


Correct, Apache Tomcat. or just Tomcat.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Updated: "Invalid character constant", Help needed