http://weblogs.sqlteam.com/jeffs/archive/2004/03/22/1085.aspx
CREATE PROCEDURE ReturnPage(@Select varchar(1000), @OrderBy varchar(1000),
@StartRow int, @EndRow int)
AS
BEGIN
declare @ColList varchar(2000);
declare @Where varchar(2000);
declare @i int;
declare @i2 int;
declare @tmp varchar(1000);
declare @dec varchar(1000);
declare @f varchar(100);
declare @d varchar(100);
declare @Symbol char(2);
declare @SQL varchar(5000);
declare @Sort varchar(1000);
set @Sort = @OrderBy + ', '
set @dec = ''
set @Where = ''
set @SQL = ''
set @i = charindex(',' , @Sort)
while @i != 0
begin
set @tmp = left(@Sort,@i-1)
set @i2 = charindex(' ', @tmp)
set @f = ltrim(rtrim(left(@tmp,@i2-1)))
set @d = ltrim(rtrim(substring(@tmp,@i2+1,100)))
set @Sort = rtrim(ltrim(substring(@Sort,@i+1,100)))
set @i = charindex(',', @Sort)
set @symbol = case when @d = 'ASC' then '>' else '<' end +
case when @i=0 then '=' else '' end
set @dec = @dec + 'declare @' + @f + ' sql_variant; '
set @ColList = isnull(replace(replace(@colList,'>','='),'<','=') + ' and ','') +
@f + @Symbol + ' @' + @f
set @Where = @Where + ' OR (' + @ColList + ') '
set @SQL = @SQL + ', @' + @f + '= ' + @f
end
set @SQL = @dec + ' ' +
'SET ROWCOUNT ' + convert(varchar(10), @StartRow) + '; ' +
'SELECT ' + substring(@SQL,3,7000) + ' from (' + @Select + ') a ORDER BY ' +
@OrderBy + '; ' + 'SET ROWCOUNT ' +
convert(varchar(10), 1 + @EndRow - @StartRow) + '; ' +
'select * from (' + @Select + ') a WHERE ' +
substring(@Where,4,7000) + ' ORDER BY ' + @OrderBy + '; SET ROWCOUNT 0;'
exec(@SQL)
END
Tuesday, December 09, 2008
Monday, December 08, 2008
Thursday, October 30, 2008
Tuesday, September 30, 2008
Friday, September 26, 2008
quacl.style.left=width/2.25;
quacl.style.top=height/2.5;
quacl.position="fixed";
Element.show('quacl');
function getScreenMiddleHeight(){
var screenW = 640, screenH = 480;
if (parseInt(navigator.appVersion)>3) {
screenH = screen.height;
}
else if (navigator.appName == "Netscape"
&& parseInt(navigator.appVersion)==3
&& navigator.javaEnabled()
)
{
var jToolkit = java.awt.Toolkit.getDefaultToolkit();
var jScreenSize = jToolkit.getScreenSize();
screenH = jScreenSize.height;
}
return screenH/2;
}
function getScreenMiddleWidth(){
var screenW = 640;
if (parseInt(navigator.appVersion)>3) {
screenW = screen.width;
}
else if (navigator.appName == "Netscape"
&& parseInt(navigator.appVersion)==3
&& navigator.javaEnabled()
)
{
var jToolkit = java.awt.Toolkit.getDefaultToolkit();
var jScreenSize = jToolkit.getScreenSize();
screenW = jScreenSize.width;
}
return screenW/2;
}
quacl.style.top=height/2.5;
quacl.position="fixed";
Element.show('quacl');
function getScreenMiddleHeight(){
var screenW = 640, screenH = 480;
if (parseInt(navigator.appVersion)>3) {
screenH = screen.height;
}
else if (navigator.appName == "Netscape"
&& parseInt(navigator.appVersion)==3
&& navigator.javaEnabled()
)
{
var jToolkit = java.awt.Toolkit.getDefaultToolkit();
var jScreenSize = jToolkit.getScreenSize();
screenH = jScreenSize.height;
}
return screenH/2;
}
function getScreenMiddleWidth(){
var screenW = 640;
if (parseInt(navigator.appVersion)>3) {
screenW = screen.width;
}
else if (navigator.appName == "Netscape"
&& parseInt(navigator.appVersion)==3
&& navigator.javaEnabled()
)
{
var jToolkit = java.awt.Toolkit.getDefaultToolkit();
var jScreenSize = jToolkit.getScreenSize();
screenW = jScreenSize.width;
}
return screenW/2;
}
Thursday, September 25, 2008
Tuesday, September 23, 2008
Tomcat datasource connection pooling
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html#Non%20DBCP%20Solutions
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html#Non%20DBCP%20Solutions
private static void initializeDataSource(String whichOne) throws NamingException, SQLException{
logger.debug("entering initializeDataSource("+whichOne+")");
try{
InitialContext ic = new InitialContext();
if(whichOne.equals(AppHelper.SC_DEFAULT_DS_CON)){
//if (dataSource == null)
dataSource = (DataSource) ic.lookup(whichOne);
}
}catch (NamingException ne){
throw new NamingException("NamingException while looking" +
" up DataSource Connection " + whichOne
+ ": \n" + ne.getMessage());
}
logger.debug("leaving initializeDataSource()");
}
Friday, September 19, 2008
Friday, September 12, 2008
creating a tld
public class myTag extends TagSupport{
}
mytag.tld
accessing in .jsp
public class myTag extends TagSupport{
}
mytag.tld
< taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0" -->
<-- description -->my excelent tag<--/ description -->
<-- display-name -->company taglib<--/ display-name -->
<-- tlib-version -->1.1<--/ tlib-version -->
<-- short-name -->mytag<--/ short-name -->
<-- uri -->http://java.sun.com/jsp/jstl/core<--/ uri -->
<-- tag -->
<-- description -->
my great tag
<--/ description -->
<-- name -->calendar<--/ name -->
<-- tag-class -->com.mypackage.Calendar<--/ tag-class -->
<-- body-content -->JSP<--/ body-content -->
<-- attribute -->
<-- description -->
the calendar obj
<--/ description -->
<-- name -->objname<--/ name -->
<-- required -->true<--/ required -->
<-- rtexprvalue -->true<--/ rtexprvalue -->
<--/ attribute -->
<--/ tag -->
<--/ taglib -->
accessing in .jsp
<%@ taglib uri="/WEB-INF/mytag.tld" prefix="mytag" %>
< mytag:calendar objname="myCalendar" />
Friday, September 05, 2008
http bot crawler
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.util.NodeList;
private void runCrawl(String url, String file)throws Exception{
URL crawlURL = new URL(url);
URLConnection yc = crawlURL.openConnection();
//sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
//String encodedUserPwd = encoder.encode("kg_b05"+":"+"*****");
//yc.setRequestProperty("Proxy-Authorization", "Basic " +encodedUserPwd);
InputStream i = yc.getInputStream();
FileOutputStream fos = new FileOutputStream(file);
int in=i.read();
while(in!=-1){
fos.write(in);
in=i.read();
}
fos.flush();
fos.close();
}
private String readFile(String file) throws Exception{
String str = "", html = "";
try {
BufferedReader in = new BufferedReader(new FileReader(file));
while ((str = in.readLine()) != null) {
html += str;
}
in.close();
} catch (IOException e) {
throw e;
}
return html;
}
public MegaVO doMegaTask() throws Exception{
runCrawl(SC_MEGA_URL, SC_MEGA_FILE);
String html = readFile(SC_MEGA_FILE);
Parser parser = new Parser();
parser.setInputHTML(html);
NodeFilter nf = new TagNameFilter("span");
NodeList spans = parser.parse (nf); // here is your two node list
Node span = null;
Node child = null;
String num = "", date = "", d1 = "", d2 = "", d3 = "", d4 = "", d5 = "", mm = "";
for(int i=0; i < spans.size(); i++){
span = spans.elementAt(i);
//if(span.getText().equals("span id=\"DrawResults2_lblMMNum1\"")){
String text = span.getText();
if(text.length() > 27){
if(text.substring(0,27).equals("span id=\"DrawResults2_lblMM")){ // 27 characters deep
String id = text.substring(27,text.length()-1);
child = span.getFirstChild();
if(id.equals("DrawNum")){
logger.info(child.getText());
num = child.getText();
}else if(id.equals("DrawDate")){
logger.info(child.getText());
date = child.getText();
}else if(id.equals("Mega")){
logger.info(child.getText());
mm = child.getText();
}else{
String n = id.substring(id.length()-1);
switch((new Integer(n)).intValue()){
case 1:
d1 = child.getText();
break;
case 2:
d2 = child.getText();
break;
case 3:
d3 = child.getText();
break;
case 4:
d4 = child.getText();
break;
case 5:
d5 = child.getText();
break;
}
logger.info(id);
logger.info(child.getText());
}
}
}
}
MegaVO vo = new MegaVO(num,date,d1,d2,d3,d4,d5,mm);
logger.info(vo.toString());
return vo;
}
Wednesday, April 30, 2008
Compression and Caching Filters
Found a plugin for FireFox which grades the performance of a web sites actions: https://addons.mozilla.org/en-US/firefox/addon/5369 it’s from Yahoo.
The main issues I found where:
* Too many javascript and css files resulting in multiple http get requests
* Not caching the javascript and css files
* Not caching images
* The javascript files were too big not minimized or obfuscated
* Not compressing the requests response back to the browser
I’ve been able to resolve these issues by using two Filters:
* Caching Filter – CacheFilter.zip also has the web.xml entries
* Compression Filter – got from http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html (CompressionFilter.zip)
I combined as many js files into one file and then did the minimizing using a tool from Yahoo: yuicompressor-2.3.5.zip
Found a plugin for FireFox which grades the performance of a web sites actions: https://addons.mozilla.org/en-US/firefox/addon/5369 it’s from Yahoo.
The main issues I found where:
* Too many javascript and css files resulting in multiple http get requests
* Not caching the javascript and css files
* Not caching images
* The javascript files were too big not minimized or obfuscated
* Not compressing the requests response back to the browser
I’ve been able to resolve these issues by using two Filters:
* Caching Filter – CacheFilter.zip also has the web.xml entries
* Compression Filter – got from http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html (CompressionFilter.zip)
I combined as many js files into one file and then did the minimizing using a tool from Yahoo: yuicompressor-2.3.5.zip
Tuesday, April 22, 2008
Need to make a priority list of future development.
Put Tina's request for page renew first, however, try and push for a test/sponsor search page next.
The ideal search page would allow for a registration agent to search for a test by test code, test name or even sponsor. As well, based on these search requests, the program would auto fill fields in the test select page in order to progress further through the application.
Knowing that ACT is in the process of updating their authorization system we may have to halt future development in order to accomplish our web service registration implementation.
Alert Dennis of the problem regarding internet access via web services.
Put Tina's request for page renew first, however, try and push for a test/sponsor search page next.
The ideal search page would allow for a registration agent to search for a test by test code, test name or even sponsor. As well, based on these search requests, the program would auto fill fields in the test select page in order to progress further through the application.
Knowing that ACT is in the process of updating their authorization system we may have to halt future development in order to accomplish our web service registration implementation.
Alert Dennis of the problem regarding internet access via web services.
Monday, April 21, 2008
Tuesday, April 08, 2008
usable log4j.properties
# Set root category priority to DEBUG and its only appender to A1.
#log4j.rootCategory=DEBUG, A1
#log4j.rootCategory=DEBUG
# A1 is set to be a ConsoleAppender.
#log4j.appender.A1=org.apache.log4j.ConsoleAppender
#log4j.appender.A1=
# A1 uses PatternLayout.
#log4j.appender.A1.layout=org.apache.log4j.PatternLayout
#log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
## New Trial Stuff
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=clockin.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
# Set root category priority to DEBUG and its only appender to A1.
#log4j.rootCategory=DEBUG, A1
#log4j.rootCategory=DEBUG
# A1 is set to be a ConsoleAppender.
#log4j.appender.A1=org.apache.log4j.ConsoleAppender
#log4j.appender.A1=
# A1 uses PatternLayout.
#log4j.appender.A1.layout=org.apache.log4j.PatternLayout
#log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
## New Trial Stuff
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=clockin.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
call java exe
http://www.csie.ntu.edu.tw/~b90008/jniexe.html
http://java.sun.com/developer/JDCTechTips/2005/tt0727.html
pass parameters to an exe:
try {
Robot robot = new Robot();
robot.delay(1000);
// Simulate a mouse click
// robot.mousePress(InputEvent.BUTTON1_MASK);
// robot.mouseRelease(InputEvent.BUTTON1_MASK);
// Simulate a key press
robot.keyPress(KeyEvent.VK_G);
robot.keyRelease(KeyEvent.VK_G);
robot.keyPress(KeyEvent.VK_K);
robot.keyRelease(KeyEvent.VK_K);
robot.keyPress(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_3);
robot.keyPress(KeyEvent.VK_6);
robot.keyRelease(KeyEvent.VK_6);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
http://www.csie.ntu.edu.tw/~b90008/jniexe.html
http://java.sun.com/developer/JDCTechTips/2005/tt0727.html
pass parameters to an exe:
try {
Robot robot = new Robot();
robot.delay(1000);
// Simulate a mouse click
// robot.mousePress(InputEvent.BUTTON1_MASK);
// robot.mouseRelease(InputEvent.BUTTON1_MASK);
// Simulate a key press
robot.keyPress(KeyEvent.VK_G);
robot.keyRelease(KeyEvent.VK_G);
robot.keyPress(KeyEvent.VK_K);
robot.keyRelease(KeyEvent.VK_K);
robot.keyPress(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_3);
robot.keyPress(KeyEvent.VK_6);
robot.keyRelease(KeyEvent.VK_6);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
Tuesday, February 12, 2008
Monday, February 11, 2008
Thursday, January 17, 2008
Subscribe to:
Posts (Atom)