Monthly Archives: 8月 2016

データベース(oracle db2 mysql)にselect topの使い方

1.oracle
select * from tableName where rownum<=n

2.infomix
select first n * from tableName

3.db2
select * row_number() over(order by col1 desc) as rownum where rownum<=n

select column from table fetch first n rows only

4.sql server
select top n * from tableName

5.sybase
set rowcount n
go
select * from tableName

6.mysql
select * from tableName limit n

7.foxpro
select * top n from table order by column

「node.js」axiosのパラメータ指定方法(Get、post)を利用するサンプル

①axiosの導入
npm
npm install axios

bower
bower install axios

②GET方法
axios.get(‘/user?ID=456’)
.then( res => {
console.info(res)
}).catch( e => {
if(e.response){
console.info(e.response.data)
console.info(e.response.status)
console.info(e.response.headers)
}else if(e.request){
console.info(e.request)
}else{
console.info(‘error’,e.message)
}
console.info(e.config)
})

③POST方法
axios.post(‘/user’, {
firstName: ‘Yamada’,
lastName: ‘Takayama’
}).then( res => {
console.info(res)
}).catch( e => {
console.info(e)
})

④nodeコード
const querystring = require(‘querystring’);
axios.post(‘http://sample.com/’, querystring.stringify({‘name’:’Yamada’}));

Java開発Exchangerを使ってスレッドサンプルコード

参考コード:
package com.jz345.javacource;
import java.util.concurrent.Exchanger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExcehangeFun {

public static void main(String[] args) {
ExecutorService service = Executors.newCachedThreadPool();
final Exchanger exchanger = new Exchanger();
service.execute(new Runnable(){
public void run() {
try{
String data1 = “testdata11”;
System.out.println(“Thread:\n” + Thread.currentThread().getName() +”test data” + data1 +”change”);
Thread.sleep((long)(Math.random()*10000));
String data2 = (String) exchanger.exchange(data1);
System.out.println(“Thread:\n” + Thread.currentThread().getName() +
“return data” + data2);
}catch(Exception e){

}
}
});

service.execute(new Runnable(){
public void run() {
try{
String data1 = “testdata22”;
System.out.println(“Thread:\n” + Thread.currentThread().getName() + “change data” + data1 +”save”);
Thread.sleep((long)(Math.random()*10000));
String data2 = (String)exchanger.exchange(data1);
System.out.println(“Thread:\n” + Thread.currentThread().getName() + “return data” + data2);
}catch(Exception e){

}
}
});
}
}

実行結果:

Thread:
pool-1-thread-1test datatestdata11change
Thread:
pool-1-thread-2change datatestdata22save
Thread:
pool-1-thread-1return datatestdata22
Thread:
pool-1-thread-2return datatestdata11

CSSでtextarea inputの枠線を消す方法

1.textareaの枠線を消す
style=’overflow:auto; background-attachment:fixed;background-repeat:no-repeat;border-style:solid;
border-color:#FFFFFF’

2.inputの枠線を消す
style=’border-left:0px;border-top:0px;border-right:0px;border-bottom:1px ‘

PHPでログファイルを書き込む方法

参考コード:
<?php
$logfile = “siterecord2016.log”;
$timezone = “+0100”; /* Timezone correction */
$lookup_size = true;
$document_root = “/usr/local/apache/share/htdocs”;
function logFileWrite($str) {
if($fd = @fopen($GLOBALS[ “logfile”], “a”)) {
fputs($fd, $str);
fclose($fd);
}
}

function getVarValue($name,$default) {
if($var = getenv($name)) {
return $var;
} else {
return $default;
}
}

if($remote_host = getVarValue( “REMOTE_HOST”, false)) {
$remote_host = getVarValue( “REMOTE_ADDR”, “-“);
}
$remote_user = getVarValue( “REMOTE_USER”, “-“);
$remote_ident = getVarValue( “REMOTE_IDENT”, “-“);
$server_port = getVarValue( “SERVER_PORT”, 80);
if($server_port!=80) {
$server_port = “:” . $server_port;
} else {
$server_port = “”;
}
$server_name = getVarValue( “SERVER_NAME”, “-“);
$request_method = getVarValue( “REQUEST_METHOD”, “GET”);
$request_uri = getVarValue( “REQUEST_URI”, “”);
$user_agent = getVarValue( “HTTP_USER_AGENT”, “”);
if($lookup_size == true && $document_root) {
$filename = ereg_replace( “\?.*”, “”, $request_uri);
$filename = “$document_root$filename”;
if(!$size = filesize($filename)) {
$size = 0;
}
} else {
$size = 0;
}

$date = gmdate( “d/M/Y:H:I:s”);
$log = “$remote_host $remote_ident $remote_user [$date $timezone] \””.
“$request_method http://$server_name$server_port$request_uri\” 200 $size\n”;

logFileWrite($log);
?>

SpringでapplicationContext.xmlを読み込む方法

方法1 classpathからxmlを読み込む
ApplicationContext context = new ClassPathXmlApplicationContext(“applicationContext.xml”);
UserDao dao = (UserDao)context.getBean(“userDao”);

方法2 ClassPathResourceを使って配置ファイルを読む
Resource cr = new ClassPathResource(“applicationContext.xml”);
BeanFactory bf=new XmlBeanFactory(cr);
UserDao userDao = (UserDao)bf.getBean(“userDao”);

方法3.FileSystemResourceを読み込む
Resource rs = new FileSystemResource(“C:/tomcat /webapps/cftpj/
WEB-INF/classes/applicationContext.xml”);
BeanFactory factory = new XmlBeanFactory(rs);
UserDao userDao = (UserDao )factory.getBean(“userDao”);
方法4.FileSystemXmlApplicationContextを読み込む
String[] path={“WebRoot/WEB-INF/applicationContext.xml”,
“WebRoot/WEB-INF/applicationContext_task.xml”};
ApplicationContext context = new FileSystemXmlApplicationContext(path);

JQueryで要素を削除する方法remove()

サンプルコード1
$(“ul li.sampleitem”).remove();
サンプルコード2
var litest = $(“#ulSite li”).remove();
$(“#ulNode2”).append(litest);
// $(“#ulSite li”).remove().appendTo($(“#ulNode2”));

jQueryで要素の前にコンテンツを挿入する方法before()とinsertBefore()

1.before()
参考コード1
$(‘.insert’).click(function(){
var str='<div>コンテンツの挿入</div>’;
$(‘#startnews24insert’).before(str);
});

参考コード2
$(‘button’).click(function(){
var str='<div>コンテンツの挿入</div>’;
$(this).before(str);
});

2.insertBefore()
参考コード3
$(‘button’).click(function(){
var str='<div>コンテンツの挿入</div>’;
$(str).insertBefore(this);
});

node.jsでnode-xlsxを使ってexcelファイルを操作する

参考コード:
var obj = xlsx.parse(‘D:/startnews24test.xlsx’);

var data = obj.worksheets[0].data;
//列数
var maxCol = obj.worksheets[0].maxCol;
//行数
var maxRow = obj.worksheets[0].maxRow;

for(var i=0;i<maxRow;i++) {
console.log(“第”+(i+1)+”行目:”);
for(var j=0;j<maxCol;j++) {
console.log(data[i][j].value);
}
}

Javaでクイックソートのアルゴリズムを使って配列の要素を並び替える

Javaコード:
public class LjsQuickSort {

public int getMiddle(Integer[] list, int low, int high) {
int tmp = list[low];
while (low < high) {
while (low < high && list[high] > tmp) {
high–;
}
list[low] = list[high];
while (low < high && list[low] < tmp) {
low++;
}
list[high] = list[low];
}
list[low] = tmp;
return low;
}
public void kanquickSort(Integer[] list, int low, int high) {
if (low < high) {
int middle = getMiddle(list, low, high);
kanquickSort(list, low, middle – 1);
kanquickSort(list, middle + 1, high);
}
}

public void quick(Integer[] str) {
if (str.length > 0) {
kanquickSort(str, 0, str.length – 1);
}
}

public static void main(String[] args) {

Integer[] list={34,16,27,12,4,8,21,30};
LjsQuickSort qs=new LjsQuickSort();
qs.quick(list);
System.out.println(“quick sort result as follows\n”);
for(int i=0;i<list.length;i++){
System.out.print(list[i]+” “);
}
System.out.println();
}

}