Sql in jsp - decrease fines by amount
hi everyone, thx for looking at my problem, well can u pls help me to sort out this problem. the situation is when someone pays his/her fines by certain amount , i need to update the fines in the database.
here is a a section of the program:
String mem_ID= request.getParameter("mem_ID");
String fines = request.getParameter("fines");
String amount = request.getParameter("amount");
int rowsAffected = SQLStatement.executeUpdate("update member set fines = (fines-'"+amount+"') where mem_ID ="+mem_ID);
thanking u in advance
hi dear,
final solution.........
String mem_ID= request.getParameter("mem_ID");
String fines = request.getParameter("fines");
String amount = request.getParameter("amount");
float newFines = Float.parseFloat(fines) - Float.parseFloat(amount);
int rowsAffected = SQLStatement.executeUpdate("update member set fines = '" + newFines + "' where mem_ID =" + mem_ID);
// unless required very high precision, avoid usage of double - u may face unpredictable results
bye for now...
Pranav
Make habit of having Dukes to share....basically, it's a give & take world
Similar Messages
-
SQL Server 2005 performance decreases with DB size while SQL Server 2012 is fine
Hi,
We have a C# windows service running that polls some files and inserts/updates some fields in database.
The service was tested on a local dev machine with SQL Server 2012 running and performance was quite decent with any number of records. Later on the service was moved to a test stage environment where SQL Server 2005 is installed. At that point database
was still empty and service was running just fine but later on, after some 500k records were written, performance problems came to light. After some more tests we've founds out that, basically, database operation performance in SQL Server 2005 decreases with
a direct correlation with the database size. Here are some testing results:
Run#
1
2
3
4
5
DB size (records)
520k
620k
720k
820k
920k
SQL Server 2005
TotalRunTime
25:25.1
32:25.4
38:27.3
42:50.5
43:51.8
Get1
00:18.3
00:18.9
00:20.1
00:20.1
00:19.3
Get2
01:13.4
01:17.9
01:21.0
01:21.2
01:17.5
Get3
01:19.5
01:24.6
01:28.4
01:29.3
01:24.8
Count1
00:19.9
00:18.7
00:17.9
00:18.7
00:19.1
Count2
00:44.5
00:45.7
00:45.9
00:47.0
00:46.0
Count3
00:21.7
00:21.7
00:21.7
00:22.3
00:22.3
Count4
00:23.6
00:23.9
00:23.9
00:24.9
00:24.5
Process1
03:10.6
03:15.4
03:14.7
03:21.5
03:19.6
Process2
17:08.7
23:35.7
28:53.8
32:58.3
34:46.9
Count5
00:02.3
00:02.3
00:02.3
00:02.3
00:02.1
Count6
00:01.6
00:01.6
00:01.6
00:01.7
00:01.7
Count7
00:01.9
00:01.9
00:01.7
00:02.0
00:02.0
Process3
00:02.0
00:01.8
00:01.8
00:01.8
00:01.8
SQL Server 2012
TotalRunTime
12:51.6
13:38.7
13:20.4
13:38.0
12:38.8
Get1
00:21.6
00:21.7
00:20.7
00:22.7
00:21.4
Get2
01:38.3
01:37.2
01:31.6
01:39.2
01:37.3
Get3
01:41.7
01:42.1
01:35.9
01:44.5
01:41.7
Count1
00:20.3
00:19.9
00:19.9
00:21.5
00:17.3
Count2
01:04.5
01:04.8
01:05.3
01:10.0
01:01.0
Count3
00:24.5
00:24.1
00:23.7
00:26.0
00:21.7
Count4
00:26.3
00:24.6
00:25.1
00:27.5
00:23.7
Process1
03:52.3
03:57.7
03:59.4
04:21.2
03:41.4
Process2
03:05.4
03:06.2
02:53.2
03:10.3
03:06.5
Count5
00:02.8
00:02.7
00:02.6
00:02.8
00:02.7
Count6
00:02.3
00:03.0
00:02.8
00:03.4
00:02.4
Count7
00:02.5
00:02.9
00:02.8
00:03.4
00:02.5
Process3
00:21.7
00:21.0
00:20.4
00:22.8
00:21.5
One more thing is that it's not Process2 table that constantly grows in size but is Process1 table, that gets almost 100k records each run.
After that SQL Server 2005 has also been installed on a dev machine just to test things and we got exactly the same results. Both SQL Server 2005 and 2012 instances are installed using default settings with no changes at all. The same goes for databases
created for the service.
So the question is - why are there such huge differences between performance of SQL Server 2005 and 2012? Maybe there are some settings that are set by default in SQL Server 2012 database that need to be set manually in 2005?
What else can I try to test? The main problem is that production SQL Server will be updated god-knows-when and we can't just wait for that.
Any suggestions/advices are more than welcome....One more thing is that it's not Process2 table that constantly grows in size but is
Process1 table, that gets almost 100k records each run....
Hi,
It is not clear to me what is that you are doing, but now we have a better understanding on ONE of your tables an it is obviously you will get worse result as the data become bigger. Actually your table look like a automatic build table by ORM like Entity
Framework, and it's DDL probably do not much your needs. For example if your select query is using a filter on the other column that [setID] then you have no index and the server probably have to scan the entire table in order to find the records that you
need.
Forum is a suitable place to seek advice about a specific system (as I mentioned before we are not familiar with your system), and it is more suitable for general questions. For example the fact that you have no index except the index on the column [setID]
can indicate a problem. Ultimately to optimize the system will need to investigate it more thoroughly (as it is no longer appropriate forum ... but we're not there yet). Another point is that now we can see that you are using [timestamp] column, an this
implies that your are using this column as a filter for selecting the data. If so, then maybe a better DDL will be to use clustered index on this column and if needed a nonclustered index on the [setID] if it is needed at all...
what is obviously is that next is to check if this DDL fit
your specific needs (as i mentioned before).
Next step is to understand what action do you do with this table. (1) what is your query which become slowly in a bigger data set. (2) Are you using ORM (object relational mapping, like Entity Framework
code first), and if so then which one.
[Personal Site] [Blog] [Facebook] -
We are in the stage of deciding which language to develop portlets. I lean towards JSP or servlets for the wide array of Java libraries we can use. I think the only advantage of PL/SQL is speed. Thanks.
It depends. If your developers are mainly Java developers, you'll probably prefer building web portlets. But if you have a strong PL/SQL skill set you could choose the latter. Additionally, if you're developing content that is database intensive you may want to build PL/SQL portlets since they transact with the database faster. If you're going to aggregate content from various web sites, using web providers is preferable. It's a matter of choice based on your requirements and preferences.
-
How to show Increase/Decrease of Sales Amount compare to Previous Month.
Hi,
My users need to view the percentage decrease/increase of Sales $ compared to previous month, for each Month.
How can I create a Restricted Key Figures that show Sales $ Amount as of Previous Month (take note it is not just Previous Month from Current Month, but each Month's Previous Month). i.e
Nov 06 - Sales $ = 1000
N0v 06 - CKF_A - Variance Compare to Prev. Month: 100%
Dec 06 - Sales $ = 800
Dec 06 - CKF_A - Variance Compare to Prev. Month: -20%
(800-1000/1000)
Jan 06 - Sales $ = 1000
Jan 06 - CKF_A - Variance Compare to Prev. Month: 25%
(1000-800/800)
How can I create CKF_A and achieve similar result?
Most of the variables for 0CALMONTH or 0FISCPER seems pointing to one value only.
I don't want to create Restricted Key Figures for each and every month.
Please help.
Thanks,
Sean Yit.Sean,
You don't have to create RKFs for each and evry month. But you need to create just two RKFs.
Lets say that you want to display the months in rows and Sales in the first column and the variance in the second column. Just restrict Sales by the month characterstic with a user entry variable (range if it is more than one month the user wants to display), then in the next column create another RKF by restricting Sales with the same month characterstic. This time offset the first varaible by minus one (-1). In the properties of this RKF, select always hide option.
Now create a CKF (calculated key figure), by using the variance% formula option.
CKF = RKF2 "%" RKF1.
I hope this helps.. -
I have a small web app that makes needs to make about 12 SQL queries in a JSP and am trying to figure out what is the best way to do this
I had initially coded this using plain JAVA code in the JSP as follows :-
<%
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
st = conn.createStatement();
rs = st.executeQuery("select .........");
%>
But then I came across the SQL Tag Library in an article and wonder if this is more efficient code?
If so does anyone have a pointer to a good intro to these tags as they look complicated (I only am doing queries on the SQL database, no inserts or updates)Sometimes you've gotta do what you've gotta do.
My rule is "no scriptlets".
If you MUST access a database from a JSP, the only right way to do it is to use JSTL <sql> tags.
% -
Integration of PL/SQL and JSP (Java Server Pages)
I need to match a web application developed with PL/SQL with another developed in JSP (Java Server Pages) the problem is that the two apps interact with the same databese, an share de same users, I need to know how to get the user and password loged into pl/sql when the user want to use same of de .jsp pages running on another application server?
Hi Michael Vstling,
Did you try the java classes library (SDOAPI) that can be downloaded from OTN?
It may provide you with a better alternative when manipulating geometries in the Java space. There is an adapter in SDOAPI which can convert a JDBC STRUCT object into Java Geometry object defined in SDOAPI, and vice versa.
There are at least two ways in mixing PL/SQL and Java. The first one, as you mentioned, is to define your custom function in terms of PL/SQL and call it from within your Java program. With SDOAPI, you have the second option, which is to define your own functions in Java using SDOAPI and deploy them as Java stored procedures in db. You can then call them from within your PL/SQL code. In either way performance depends on a lot of things and generally it requires a "try and improve" approach.
About JPublisher and sdo_ordinate_array it may not be a spatial related problem. Did you try search the Java-related forums first?
LJ -
can n e 1 tell me where i am going wrong i am trying to use sql in a jsp to try to take out specific tuples from a table in my db but it is not working. i have been looking at the code for ages and can't figure out where i'm going wrong. please help!!!!!!!!!!!
here is the code and the errors.
<%@ page import="java.sql.*, java.util.*, java.io.* " %>
<body bgcolor="#ffffcc">
<% String name = (String)session.getAttribute("thefname"); %>
<% String staffid = (String)session.getAttribute("theusername"); %>
<center>
<h2><tt> Here are the assignments you've marked :<%=name%>:<%=staffid%> </tt></h2>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection con1 = null;
Statement stmt1 = null;
ResultSet rs1 = null;
String queryStr1 = null;
try{
con1 = DriverManager.getConnection(
"jdbc:mysql://bushmouth.doc.stu.mmu.ac.uk:3306/dutts?user=*****&password=*********");
stmt1 = con1.createStatement();
queryStr1 = "SELECT *
FROM e modresults, d module
WHERE e.modid = d.modid
And d.staffid = '" + staffid + "'";
rs1 = stmt1.executeQuery(queryStr1);
%>
<center>
<H2 color="#99ffff"><tt> All submited assignments</tt></h2>
<hr>
<br>
<table border="1" bgcolor="#66ccff" >
<tr>
<th> modid</th>
<th>courseid</th>
<th>studentid</th>
<th> assessmentno</th>
<th> url</th>
<th> grade</th>
<th>tutorcomment </th>
</tr>
<%
while (rs1.next())
String modid = rs1.getString(1);
String courseid = rs1.getString(2);
String studentid = rs1.getString(3);
String assessmentno = rs1.getString(4);
String url = rs1.getString(5);
String grade = rs1.getString(6);
String tutorcomment = rs1.getString(7);
%>
<tr><td><%=modid%></td>
<td><%=courseid%></td>
<td><%=studentid%></td>
<td><%=assessmentno%></td>
<td><a href="<%=url%>"><%=url%></a></td>
<td><%=grade%></td>
<td><%=tutorcomment%></td></tr>
</center>
<%
} // end while()
}catch(SQLException s){%> <%= s%> <% }
finally{
// clean up.
try{
if (rs1!=null) rs1.close();
if (stmt1!=null) stmt1.close();
if (con1!=null) con1.close();
}catch(SQLException s){}
%>
</TABLE>
<br>
<button style="width:200;height:45"
onClick="history.go(-1)"><b>back to account</b></button>
</body>
</center>
</body>
rg.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 16 in the jsp file: /jsp/vmarked.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\tomcat\work\Standalone\localhost\student_mod2_dutts\jsp\vmarked_jsp.java:74: unclosed string literal
queryStr1 = "SELECT *
^
An error occurred at line: 16 in the jsp file: /jsp/vmarked.jsp
Generated servlet error:
C:\tomcat\work\Standalone\localhost\student_mod2_dutts\jsp\vmarked_jsp.java:77: unclosed character literal
And d.staffid = '" + staffid + "'";
^
2 errorsthanks for that guys it has sorted that out. but i still have 1 little problem with it. i am getting the following error when i try to use that sql command
java.sql.SQLException: General error: Table 'dutts.e' doesn't exist
i know it's not really a java problem , but can i be cheeky enough to ask if some one could see if i have written my sql statement correctly?
here is the statement i have written
queryStr1 = "SELECT * FROM e modresults, d module WHERE e.modid = d.modid And d.staffid = '" + staffid + "'"; -
Explain plan output for a sql in JSP page
Hello all,
I have a requirement to give SQL query as an input and get the output and explain plan in the same JSP page. i could get the SQL result, but i want to get the EXPLAIN Plan.
can any one help me in this.
Thanks
KiranHello all,
I have a requirement to give SQL query as an input and get the output and explain plan in the same JSP page. i could get the SQL result, but i want to get the EXPLAIN Plan.
can any one help me in this.
Thanks
Kiran -
Hi everybody,
i started to program in JSP only from yesterday and i'd like to execute a statement SQL from my JSP page....
My code is
<%Class.forName("oracle.jdbc.driver.OracleDriver");%>
<%java.sql.Connection c = java.sql.DriverManager.getConnection("ora817", "protocs", "protocs");%>
<% try {
Statement dbst = c.createStatement();
ResultSet rs;
rs = dbst.executeQuery("update upload_status set stato= 4;");
c.close ();
catch (SQLException e) {
out.println("Non riesco a fare l'update "+e);
return;
%>
So when i use use JDeveloper and i run the project i obtain the following error
500 Internal Server Error
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at untitled1.jspService(untitled1.jsp:17)
[untitled1.jsp]
at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:139)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:347)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:778)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
at java.lang.Thread.run(Thread.java:534)
I hope that some one can help meLet's see.
You don't have the Oracle JDBC driver JAR in the CLASSPATH. Put it in WEB-INF/lib in your Web app's WAR file.
Your Oracle database URL is totally wrong. It should look something like this:
jdbc:oracle:thin:@host:1521:database
You should separate out that JDBC code and test it in a separate object on the command line before you try sticking it into a JSP. At least make sure that you know how to connect to the database.
Sounds like you need these:
http://java.sun.com/docs/books/tutorial/jdbc/
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
MOD -
Anybody using Hypersonic SQL in JSP?
Hello,
Does anybody use Hypersonic SQL?
I implement a guestbook system with JSP that
saves data in Hypersonic SQL. This system
runs on www.mycgiserver.com. My JSP program
has thread safe option set to false to make
sure one thread is reading and writing the database
at a time. However, every once in a while, the
database will be wiped out mysteriously.
So I am just wondering that this happens to
anyone else? Is this a Hypersonic SQL's bug
or it's the server that goofs up or I did something
wrong with the JSP setting? Any ideas or
comments please? Thanks !!!Hi there!
I use Hypersonic locally and on mycgiserver.com. Luckilly, I haven't encountered your problems so far. I use a similar approach, I have a bean that handles a singleton-connection to the DB, and that will queue up all requests. But so far , I haven't had that much load on the app, so maybe I'll get back in this matter, with the same problem... Anyone att mycgiserver that had an id�a?
regards
Markus -
Need an information using java.sql in jsp
I found that there is a 'dataset' like architecture in .NET, is there any 'dataset' like substance in our java, if it is means can you give me some ideas for using it in jsp, give me some example for saving a record in the mysql database. very urgent please,
KIRUPA_SHANKAR wrote:
I found that there is a 'dataset' like architecture in .NET, is there any 'dataset' like substance in our java, if it is means can you give me some ideas for using it in jsp, give me some example for saving a record in the mysql database. Shouldn't be doing database stuff in JSPs. Use JSTL and its <sql> tags if you must.
RowSet might be close. I don't write .NET.
very urgent please,Not to me.
% -
This part of code is not working properly as the JSP code has not been encorporated properly in the sql statement after LIKE.
java.sql.ResultSet RS = statement.executeQuery("SELECT BookID, Ebook.AuthorID, Surname, BookTitle, FileSize, Description, Price, Image FROM Author INNER JOIN Ebook ON Author.AuthorID = Ebook.AuthorID WHERE BookTitle LIKE '*" + bookTitle2 + "*' AND Surname LIKE '*" + surname2 + "*'");
It doesn't display the shopping cart but if I change the sql code to:
WHERE BookTitle LIKE '* queen *' AND Surname LIKE '**'
It works so I know its not the SQL code. I have included the code for the entire page below in case you spot any glaring mistakes.
<%@ page language="java" contentType="text/html"
import="ShoppingBasket,Product"
errorPage="errorpage.jsp" %>
<html>
<head> <title>Search Results</title></head>
<body>
<table width="80%" border="0" cellspacing="5" cellpadding="1">
<tr>
<td width = "15%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Search
Results</font></b></td>
<td width = "10%">�</td>
<td width = "15%">�</td>
<td width = "15%">�</td>
<td width = "20%">�</td>
<td width = "5%">�</td>
<td width = "10%">�</td>
<td width = "5%">�
<td width="10%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><a href="<%= response.encodeURL(shop-basket.jsp") %">"><img src="images\viewbasket.gif" border="0" alt="View Basket"></a></font></td>
</tr>
<tr>
<td width = "15%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width = "10%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">E-Book
No.</font></b></td>
<td width = "15%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Title</font></b></td>
<td width = "15%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Author</font></b></td>
<td width = "20%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Story
Line</font></b></td>
<td width = "5%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">File
Size</font></b></td>
<td width = "10%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Price</font></b></td>
<td width = "5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Read
Reviews</b> </font>
<td width="10%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
</tr>
<%
String bookTitle2 = request.getParameter("bookTitle");
bookTitle2 = bookTitle2.replaceAll("'", "''");
String surname2 = request.getParameter("surname");
surname2 = surname2.replaceAll("'", "''");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:odbc:Novbase","","");
java.sql.Statement statement = connection.createStatement();
java.sql.ResultSet RS = statement.executeQuery("SELECT BookID, Ebook.AuthorID, Surname, BookTitle, FileSize, Description, Price, Image FROM Author INNER JOIN Ebook ON Author.AuthorID = Ebook.AuthorID WHERE BookTitle LIKE '*" + bookTitle2 + "*' AND Surname LIKE '*" + surname2 + "*'");
int rowCounter = 0;
while(RS.next())
String image = RS.getString("Image");
String bookID = RS.getString("BookID");
String title = RS.getString("BookTitle");
String surname = RS.getString("Surname");
String storyLine = RS.getString("Description");
String fileSize = RS.getString("FileSize");
String price = RS.getString("price");
rowCounter++;
String bg = (rowCounter %2 !=0) ? "#C0C0C0" : "#FFFFFF";
%>
<tr bgcolor="<%= bg %>">
<td width="15%" valign="top" align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><img src="<%= image %>"></font></td>
<td width="10%" valign="top" align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%= bookID %></font></td>
<td width="10%" valign="top" align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%= title %></font></td>
<td width="10%" valign="top" align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%= surname %></font></td>
<td width="10%" valign="top" align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%= storyLine %></font></td>
<td width="5%" valign="top" align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%= fileSize %>MB</font></td>
<td width="10%" valign="top" align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">?<%= price %></font></td>
<td width="10%" valign="top" align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
review</font></td>
<td width="10%" align="center" valign="top"><a href="<%= response.encodeURL("shop-products.jsp?title="+title+"&bookID="+bookID+"&price="+price) %> ">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1"><img src="images\addtobasket.gif" border="0" alt="Add To Basket"></font></a></td>
</tr>
<%
RS.close();
connection.close();
%>
</table>
this is the contents of the surname field <%= surname2 %><br>
this is the contents of the title field <%= bookTitle2 %>
<jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
<% String title = request.getParameter("BookTitle");
if(title!=null)
String bookID = request.getParameter("BookID");
double price = Double.parseDouble(request.getParameter("Price"));
Product item = new Product(bookID, title, price);
basket.addProduct( item );
%>
</body>
</html></a>found the answer. Wildcard should be like this:
'%" + bookTitle + "%' -
HI,
I'm new to adobe and would really appreciate some help! I'm trying to follow a Lynda tutorial and we are using the line art tool, I was doing fine until he's mentioned you can use the arrows to increase/decrease the number of segments in the spiral, bulls eye etc. He seems to be able to go up and down gradually where as I jump from, say, 8 to zero or down to two or none. Any help is appreciated, Thanks.lindenblossoms,
You may have a look at Edit>Preferences>General>Keyboard Increment, at least to start with. -
Performing SQL in JSP okay for clustering?
I'm running on WLS 8.1 SP2. I've a JSP which is part of my main post login page. There're some SQL logics there. Would this be a problem to cluster replication & failover?
thanks for that guys it has sorted that out. but i still have 1 little problem with it. i am getting the following error when i try to use that sql command
java.sql.SQLException: General error: Table 'dutts.e' doesn't exist
i know it's not really a java problem , but can i be cheeky enough to ask if some one could see if i have written my sql statement correctly?
here is the statement i have written
queryStr1 = "SELECT * FROM e modresults, d module WHERE e.modid = d.modid And d.staffid = '" + staffid + "'"; -
SQL Query to add previous month amount to current month amount
Beginner - Using SQL 2008 R2 - Having a difficult time adding previous month amount to current month amount on a continual running basis. Table fields and example data are:
FunctionID
UnitID
Dateof
Result YTD
A AA 01/01/2014 10 10
A AA 02/01/2014 10
20
A AA 03/01/2014 15
35
B BB 01/01/2014 20
20
B BB 02/01/2014 10 30
The YTD field would be a calculated field. I would need to be able start a new YTD in Jan of the next year. Really could use some help and direction on this one. Easy to do in an Excel spreadsheet. Can't seem to get it in SQL. Thanks in advance.As of 2008 R2 the choices are:
- Self join
- Correlated subquery (in the SELECT or APPLY clauses)
- Cursor
- SQLCLR aggregation function (winner)
The first two options yield a poor performance for tables with considerable number of rows.
Example:
select
A.*,
select
sum(B.Result)
from
T as B
where
B.FunctionID = A.FunctionID
and B.UnitID = A.UnitID
and B.Dateof >= dateadd(year, datediff(year, '19000101', A.Dateof), '19000101') --bofyear
and B.Dateof <= A.Dateof
) as YTD
from
T as A;
Check these old but very interesting posts from Adam Machanic.
http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-redux.aspx
http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-yet-again-sqlclr-saves-the-day.aspx
The things get easier from SS 2012 with the enhanced OVER clause (introduction of window frame extent).
select
sum(Result) over(
partition by FunctionID, UnitID, year(Dateof)
order by Dateof
rows between unbounded preceding and current row
) as YTD
from
T;
http://sqlmag.com/sql-server-2012/sql-server-2012-how-write-t-sql-window-functions-part-3
AMB
Some guidelines for posting questions...
AYÚDANOS A AYUDARTE, guía básica de consejos para formular preguntas
Maybe you are looking for
-
Csv output stop working after upgrade
We just did a apex 3.2 to 4.0 upgrade, then all csv output links stop working. How can I fix the problem? Any suggestions are greatly appreciated. A sample link is shown in following, which give page not found error http://c2apex:7777/pls/apex/f?p=10
-
Hello, My company is not subscribing www.bwexpertonline.com magazine so if anybody in this forum having subscription could you please post here Here are Artical Information 1. Nathan Genez, Develop a Custom DataSource Using the Generic Extractor (BW/
-
Cancel button to display confirmation dialog in an edittable form
Hi everyone. I have got a requirement that in my edittable form, I need to show confirmation popup before canelling the page and discarding all the changes. But, before showing that dialog, I need to figure out if any changes happened or not? As usua
-
Aloha, Would someone please take a moment to look at the link, www.reefcheckhawaii.org/newindex.html The link states and colors are as they should be in the navigation bar on the left, however, the image links on the right are functional but don't di
-
Strange problem with SQLPLUS when client and server on the same box
Hi, I have the problem with SQLPLUS when clinet and server on the same machine. With client and server on the same machine i am running the command sqlplus -l username/password@connect_identifier as SYSDBA. With this command, even if you pass in wron