Jan
24
参考这里的教程写的: http://www.developer.com/article.php/3417381
同时也终于知道了stmt原来是Statement的简写,惭愧。。。
同时也终于知道了stmt原来是Statement的简写,惭愧。。。
import java.sql.*;
public class Jdbc11 {
public static void main (String args[]) {
try {
Class.forName("com.mysql.jdbc.Driver");
Statement stmt = null;
String url = "jdbc:mysql://localhost:3306/test";
String dbuser = "root";
String dbpass = "123456";
String dbname = "felix021";
String tblname = "users";
Connection con = DriverManager.getConnection(url, dbuser, dbpass);
stmt = con.createStatement();
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
//建库
stmt.executeUpdate("CREATE DATABASE IF NOT EXISTS " + dbname);
stmt.executeUpdate("USE " + dbname);
//建表
stmt.executeUpdate("DROP TABLE IF EXISTS " + tblname);
stmt.executeUpdate(
"CREATE TABLE " + tblname + "(\n" +
" `id` INT PRIMARY KEY AUTO_INCREMENT, \n" +
" `name` CHAR(20) NOT NULL, \n" +
" `description` varchar(255) DEFAULT NULL\n" +
")"
);
//插入
int count = stmt.executeUpdate(
"INSERT INTO " + tblname + "\n" +
"(`id`, `name`, `description`) VALUES \n" +
"(NULL, 'a', 'ooxx'), \n" +
"(NULL, 'b', NULL), \n" +
"(NULL, 'c', 'haha'), \n" +
"(NULL, 'd', 'hoho')"
);
System.out.println("Inserted " + count + " rows");
//statement for resultset
stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
//查询
ResultSet rs = stmt.executeQuery("SELECT * FROM " + tblname);
System.out.println("All results are listed below:");
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
String description = rs.getString("description");
System.out.println(
"id=" + id + ", " +
"the name is " + name + ", " +
description
);
}
//删表
stmt.executeUpdate("DROP TABLE " + tblname);
//删库
stmt.executeUpdate("DROP DATABASE " + dbname);
}
catch (SQLException sqlE) {
System.out.println("SQL Error: " + sqlE);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public class Jdbc11 {
public static void main (String args[]) {
try {
Class.forName("com.mysql.jdbc.Driver");
Statement stmt = null;
String url = "jdbc:mysql://localhost:3306/test";
String dbuser = "root";
String dbpass = "123456";
String dbname = "felix021";
String tblname = "users";
Connection con = DriverManager.getConnection(url, dbuser, dbpass);
stmt = con.createStatement();
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
//建库
stmt.executeUpdate("CREATE DATABASE IF NOT EXISTS " + dbname);
stmt.executeUpdate("USE " + dbname);
//建表
stmt.executeUpdate("DROP TABLE IF EXISTS " + tblname);
stmt.executeUpdate(
"CREATE TABLE " + tblname + "(\n" +
" `id` INT PRIMARY KEY AUTO_INCREMENT, \n" +
" `name` CHAR(20) NOT NULL, \n" +
" `description` varchar(255) DEFAULT NULL\n" +
")"
);
//插入
int count = stmt.executeUpdate(
"INSERT INTO " + tblname + "\n" +
"(`id`, `name`, `description`) VALUES \n" +
"(NULL, 'a', 'ooxx'), \n" +
"(NULL, 'b', NULL), \n" +
"(NULL, 'c', 'haha'), \n" +
"(NULL, 'd', 'hoho')"
);
System.out.println("Inserted " + count + " rows");
//statement for resultset
stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
//查询
ResultSet rs = stmt.executeQuery("SELECT * FROM " + tblname);
System.out.println("All results are listed below:");
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
String description = rs.getString("description");
System.out.println(
"id=" + id + ", " +
"the name is " + name + ", " +
description
);
}
//删表
stmt.executeUpdate("DROP TABLE " + tblname);
//删库
stmt.executeUpdate("DROP DATABASE " + dbname);
}
catch (SQLException sqlE) {
System.out.println("SQL Error: " + sqlE);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Jan
23
php代码
侧边栏的内容:
<?php
define ("MAX_MSG_COUNT", 5);
define ("USER_NAME", 'felix021');
$msg_c = isset($_GET['c']) ? intval($_GET['c']) : MAX_MSG_COUNT;
$user = isset($_GET['u']) ? $_GET['u'] : USER_NAME;
require ('../lib/twitter.php'); //注: 此文件从twitese的lib目录下提取,并增加了
//define("API_URL", "http://twitter.com");
$t = new twitter();
$s = $t->userTimeline(1, $user);
$msg = array();
for ($i = 0; $i < $msg_c; $i++) {
$msg[$i] = htmlspecialchars(stripslashes($s[$i]->text));
$msg[$i] = preg_replace(
array(
"/(\w+):\/\/([a-zA-Z0-9\.\/\-%+\?#_=@:&;])*/i",
'/(\s|^)@([a-zA-Z0-9_-]+)/',
'/(\s|^)#([a-zA-Z0-9_-]+)/',
),
array(
'<a href="\0" target="_blank">\0</a>',
'\1<a href="/t/\2" target="_blank">@\2</a>',
'\1<a href="/t/~\2" target="_blank">#\2</a>',
),
$msg[$i]
);
}
echo json_encode($msg);
?>
define ("MAX_MSG_COUNT", 5);
define ("USER_NAME", 'felix021');
$msg_c = isset($_GET['c']) ? intval($_GET['c']) : MAX_MSG_COUNT;
$user = isset($_GET['u']) ? $_GET['u'] : USER_NAME;
require ('../lib/twitter.php'); //注: 此文件从twitese的lib目录下提取,并增加了
//define("API_URL", "http://twitter.com");
$t = new twitter();
$s = $t->userTimeline(1, $user);
$msg = array();
for ($i = 0; $i < $msg_c; $i++) {
$msg[$i] = htmlspecialchars(stripslashes($s[$i]->text));
$msg[$i] = preg_replace(
array(
"/(\w+):\/\/([a-zA-Z0-9\.\/\-%+\?#_=@:&;])*/i",
'/(\s|^)@([a-zA-Z0-9_-]+)/',
'/(\s|^)#([a-zA-Z0-9_-]+)/',
),
array(
'<a href="\0" target="_blank">\0</a>',
'\1<a href="/t/\2" target="_blank">@\2</a>',
'\1<a href="/t/~\2" target="_blank">#\2</a>',
),
$msg[$i]
);
}
echo json_encode($msg);
?>
侧边栏的内容:
<div id="twitter" style="font-size:12px"></div>
<script>
function getXML() {
var a = null;
try {
if (window.XMLHttpRequest) {
a = new XMLHttpRequest();
} else if (window.ActiveXObject) {
a = new ActiveXObject("Msxml2.XMLHTTP");
}
}catch(e) {}
return a;
}
function _t(c) {
var x = getXML();
x.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
var g = eval(this.responseText);
var tt = '';
var t = document.getElementById('twitter');
for(var i = 0; i < g.length; i++){
tt += g[i] + (i+1 == g.length ? "" : "<hr/>");
}
t.innerHTML = tt;
}
}
x.open("GET", "/blog/tt.php?c="+c, true);
x.send('');
}
_t(4);
</script>
<script>
function getXML() {
var a = null;
try {
if (window.XMLHttpRequest) {
a = new XMLHttpRequest();
} else if (window.ActiveXObject) {
a = new ActiveXObject("Msxml2.XMLHTTP");
}
}catch(e) {}
return a;
}
function _t(c) {
var x = getXML();
x.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
var g = eval(this.responseText);
var tt = '';
var t = document.getElementById('twitter');
for(var i = 0; i < g.length; i++){
tt += g[i] + (i+1 == g.length ? "" : "<hr/>");
}
t.innerHTML = tt;
}
}
x.open("GET", "/blog/tt.php?c="+c, true);
x.send('');
}
_t(4);
</script>
Jan
22
RewriteEngine On
RewriteBase /t
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^~@].*)$ user.php?id=$1 [QSA,L]
RewriteRule ^(@.*)$ search.php?q=$1 [QSA,L]
RewriteRule ^~(.*)$ search.php?q=$1 [QSA,L]
RewriteBase /t
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^~@].*)$ user.php?id=$1 [QSA,L]
RewriteRule ^(@.*)$ search.php?q=$1 [QSA,L]
RewriteRule ^~(.*)$ search.php?q=$1 [QSA,L]
Jan
20
世界上最贵的网站出现在中国,而不是欧美等国家,充分体现了中国特色社会主义的优越性。
传送门:http://www.mof.gov.cn/mof/xinxi/zhongyangbiaoxun/zhongbiaogonggao/200912/t20091215_246271.html
为防止一小撮别有用心的人消灭社会主义的建设成果,特此存截图留念。

p.s. 还有一个670w造价的网站,传送门:
http://www.mof.gov.cn/mof/xinxi/zhongyangbiaoxun/zhongbiaogonggao/200912/t20091230_254406.html
相比之下一个150w造价的3间厕所,实在上不了台面啊!
@ 20100121 p.s.
rtmeme: RT @yuanxinting RT @xiaomi2020: 国家汉办3520万元建立网络孔子学院。中标公司是五洲汉风网络科技(北京)有限公司。该公司法人代表是胡志平。其另一职务是国家汉办副主任。也就是国家汉办开出了标书,是国家汉办创建了企业
@ 20100122 p.s.
此新闻已经开始被和谐,详见:Google搜索 中国工会网扩建项目 网易
传送门:http://www.mof.gov.cn/mof/xinxi/zhongyangbiaoxun/zhongbiaogonggao/200912/t20091215_246271.html
为防止一小撮别有用心的人消灭社会主义的建设成果,特此存截图留念。
p.s. 还有一个670w造价的网站,传送门:
http://www.mof.gov.cn/mof/xinxi/zhongyangbiaoxun/zhongbiaogonggao/200912/t20091230_254406.html
相比之下一个150w造价的3间厕所,实在上不了台面啊!
@ 20100121 p.s.
rtmeme: RT @yuanxinting RT @xiaomi2020: 国家汉办3520万元建立网络孔子学院。中标公司是五洲汉风网络科技(北京)有限公司。该公司法人代表是胡志平。其另一职务是国家汉办副主任。也就是国家汉办开出了标书,是国家汉办创建了企业
@ 20100122 p.s.
此新闻已经开始被和谐,详见:Google搜索 中国工会网扩建项目 网易
Jan
20
折腾了好久才弄出来,sigh,不熟这东西
引用
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} /(index\.php)?
RewriteRule ^.*$ - [L]
RewriteCond %{HTTP_HOST} 19880711\.com
RewriteRule ^(.*)$ http://www.felix021.com/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} /(index\.php)?
RewriteRule ^.*$ - [L]
RewriteCond %{HTTP_HOST} 19880711\.com
RewriteRule ^(.*)$ http://www.felix021.com/$1 [QSA,L]
Jan
19
给Windows 7设置环境变量的时候,在用于分隔各个路径的分号前后,不要为了容易分辨而加上空格,否则你会死的很难看。
这就是经过十五分钟后我才发现的,让我吐血的教训。
这就是经过十五分钟后我才发现的,让我吐血的教训。
Jan
18
今天windy在群里提出一个问题: 为什么下面这段代码输出了why?
因为已经有结果了,反推过去,很容易就会想到,php把字符串当作数组来用了。再通过
由于此结论仅为猜测,想进一步证实,但是对php代码不熟悉,翻了zend_hash.c等文件都没找到北,因此请教了雪候鸟大人,得知真正的处理代码位于
@ php-5.2.8/Zend/zend_execute.c +1026
具体实现的代码是
简单写了一点注释,只能大致看懂逻辑,其他边边角角的,暂时就没时间看了:'(
$arr = 'windy';
if (isset($arr['why'])) {
echo 'why';
}
if (isset($arr['why'])) {
echo 'why';
}
因为已经有结果了,反推过去,很容易就会想到,php把字符串当作数组来用了。再通过
echo $arr['why'];
验证一下,发现输出的是w, 也就是$arr{0}的值,可以大致得出一个结论:当把字符串当作数组使用的时候,会自动把索引转换成整形,然后再当作字符串的偏移量读取返回。由于此结论仅为猜测,想进一步证实,但是对php代码不熟悉,翻了zend_hash.c等文件都没找到北,因此请教了雪候鸟大人,得知真正的处理代码位于
@ php-5.2.8/Zend/zend_execute.c +1026
static void zend_fetch_dimension_address(temp_variable *result, zval **container_ptr, zval *dim, int dim_is_tmp_var, int type TSRMLS_DC)
这个函数的作用是:将container_ptr所指向的container这个容器中,索引为dim的值取出放在result所指定的内存中去。具体实现的代码是
1063 switch (Z_TYPE_P(container)) {
1064 zval **retval;
....
1099 case IS_STRING: { //如果这个容器是string
1100 zval tmp;
1101
1102 if (dim == NULL) {
1103 zend_error_noreturn(E_ERROR, "[] operator not supported for strings");
1104 }
1105
1106 if (Z_TYPE_P(dim) != IS_LONG) { //如果偏移量的类型不是LONG
1107 switch(Z_TYPE_P(dim)) {
1108 /* case IS_LONG: */
1109 case IS_STRING:
1110 case IS_DOUBLE:
1111 case IS_NULL:
1112 case IS_BOOL:
1113 /* do nothing */ //允许STRING, DOUBLE, NULL, BOOL四种类型
1114 break;
1115 default: //其他类型都报错
1116 zend_error(E_WARNING, "Illegal offset type");
1117 break;
1118 }
1119
1120 tmp = *dim;
1121 zval_copy_ctor(&tmp);
1122 convert_to_long(&tmp);
1123 dim = &tmp; //将原来的dim转换成LONG
1124 }
1125 switch (type) {
1126 case BP_VAR_R:
1127 case BP_VAR_IS:
1128 case BP_VAR_UNSET:
1129 /* do nothing... */
1130 break;
1131 default:
1132 SEPARATE_ZVAL_IF_NOT_REF(container_ptr);
1133 break;
1134 }
1135 if (result) { //存放结果
1136 container = *container_ptr;
1137 result->str_offset.str = container;
1138 PZVAL_LOCK(container);
1139 result->str_offset.offset = Z_LVAL_P(dim);
1140 result->var.ptr_ptr = NULL;
1141 if (type == BP_VAR_R || type == BP_VAR_IS) {
1142 AI_USE_PTR(result->var);
1143 }
1144 }
1145 return;
1146 }
1147 break;
1064 zval **retval;
....
1099 case IS_STRING: { //如果这个容器是string
1100 zval tmp;
1101
1102 if (dim == NULL) {
1103 zend_error_noreturn(E_ERROR, "[] operator not supported for strings");
1104 }
1105
1106 if (Z_TYPE_P(dim) != IS_LONG) { //如果偏移量的类型不是LONG
1107 switch(Z_TYPE_P(dim)) {
1108 /* case IS_LONG: */
1109 case IS_STRING:
1110 case IS_DOUBLE:
1111 case IS_NULL:
1112 case IS_BOOL:
1113 /* do nothing */ //允许STRING, DOUBLE, NULL, BOOL四种类型
1114 break;
1115 default: //其他类型都报错
1116 zend_error(E_WARNING, "Illegal offset type");
1117 break;
1118 }
1119
1120 tmp = *dim;
1121 zval_copy_ctor(&tmp);
1122 convert_to_long(&tmp);
1123 dim = &tmp; //将原来的dim转换成LONG
1124 }
1125 switch (type) {
1126 case BP_VAR_R:
1127 case BP_VAR_IS:
1128 case BP_VAR_UNSET:
1129 /* do nothing... */
1130 break;
1131 default:
1132 SEPARATE_ZVAL_IF_NOT_REF(container_ptr);
1133 break;
1134 }
1135 if (result) { //存放结果
1136 container = *container_ptr;
1137 result->str_offset.str = container;
1138 PZVAL_LOCK(container);
1139 result->str_offset.offset = Z_LVAL_P(dim);
1140 result->var.ptr_ptr = NULL;
1141 if (type == BP_VAR_R || type == BP_VAR_IS) {
1142 AI_USE_PTR(result->var);
1143 }
1144 }
1145 return;
1146 }
1147 break;
简单写了一点注释,只能大致看懂逻辑,其他边边角角的,暂时就没时间看了:'(
Jan
18
@ php-5.2.8/Zend/zend_builtin_functions.c
1120 #ifdef ZEND_TEST_EXCEPTIONS
1121 ZEND_FUNCTION(crash)
1122 {
1123 char *nowhere=NULL;
1124
1125 memcpy(nowhere, "something", sizeof("something"));
1126 }
1127 #endif
1121 ZEND_FUNCTION(crash)
1122 {
1123 char *nowhere=NULL;
1124
1125 memcpy(nowhere, "something", sizeof("something"));
1126 }
1127 #endif