Skip to content

Instantly share code, notes, and snippets.

@MangoLiu
MangoLiu / tableRows
Created October 8, 2014 08:38
获取数据表的行数
select count(*)
from 表名
where 条件
@MangoLiu
MangoLiu / QEset
Created October 8, 2014 08:29
QE设定
set mapred.job.priority=VERY_HIGH;
set mapred.job.map.capacity = 1000;
set mapred.reduce.capacity=150;
@MangoLiu
MangoLiu / connectDB
Created February 9, 2014 03:31
java环境下连接MySQL
1 下载mysql(http://www.mysql.cn/),解压并安装。
若安装之后,可以打开mysql.exe,说明安装成功。
2 打开mysql.exe之后,输入mysql命令,建库/建表/插入...
3 下载JDBC驱动(http://mysql.ntu.edu.tw/Downloads/Connector-J/mysql-connector-java-5.0.8.zip)
(JDBC驱动是与java程序的接口, 使java语言开发的程序可以连接使用sql数据库。)
4 将JDBC驱动(即其中的jar包,在这里叫做mysql-connector-java-5.0.8-bin.jar)导入到工程中:
工程上右键,选择Build Path--->Configure Build Path--->Libraries--->Add External JARs--->导入jar包
@MangoLiu
MangoLiu / sql
Last active August 29, 2015 13:56
常用数据库命令
1:使用SHOW语句找出在服务器上当前存在什么数据库:
mysql> SHOW DATABASES;
2:创建一个数据库MYSQLDATA
mysql> CREATE DATABASE MYSQLDATA;
3:选择你所创建的数据库
mysql> USE MYSQLDATA; (按回车键出现Database changed 时说明操作成功!)
4:查看现在的数据库中存在什么表
@MangoLiu
MangoLiu / NewsManager.java
Created January 1, 2014 05:49
Hibernate persistence operation (Hibernate 持久化操作的一般步骤)
public class NewsManager{
public static void main(String[] args) throws Exception{
//实例化Configuration
Configuration conf = new Configuration().configure();
//创建SessionFactory
SessionFactory sf = conf.buildSessionFactory();
//创建Session
Session session = sf.openSession();
//开始事务
Tracsaction tx = sess.beginTransaction();
@MangoLiu
MangoLiu / hibernate.cfg.xml
Last active January 1, 2016 21:39
hibernate.cfg.xml (hibernate配置文件)
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Hibernate文件头都一样-->
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 指定的数据库的url,hibernate连接数据库名,具体而定。 -->
<property name="connection.url">dbc:mysql://localhost:3306/countmanagement</property>
@MangoLiu
MangoLiu / classname.hbm.xml
Created January 1, 2014 05:16
Hibernate mapping file (Hibernate 映射文件:classname.hbm.xml)
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<!-- 以上4行,所有的配置xml文件都一样。 -->
<hibernate-mapping package="包名">
<class name="类名" table="表名"> <!-- 每个class元素对应一个持久化对象,即一个数据表。 -->
<!-- id元素定义持久化类的标识属性。 -->
<id name="类中的字段名" column="对应表中字段" type="类型 ">
<generator class="identity"/><!-- 主键生成策略 -->
@MangoLiu
MangoLiu / str2Int.java
Last active January 1, 2016 02:19
String--->int (将字符串转换为整型)
public int str2Int(String s) {
// method1
int n = Integer.parseInt(s);
// method2
int sum = 0;
int t = 1;
char[] c = s.toCharArray();
for (int i = c.length - 1; i > -1; i--) {
sum += (c[i] - '0') * t;
@MangoLiu
MangoLiu / floderProcesser.java
Created December 6, 2013 07:13
Process each file in specified the floder.(遍历并处理指定文件夹下的每一个文件)
public void floderProcesser() throws IOException {
//testfloder是一个文件夹,和.project文件在同一目录下。
String path = "test";
File f=new File(path);
File[] list=f.listFiles();
int fileNum = list.length;
String name;
for(int i = 0;i<fileNum;i++){
name = list[i].getName();
@MangoLiu
MangoLiu / resizeImage.java
Last active December 30, 2015 08:09
resize image (将图片按照指定大小输出)
public static void resizeImage(String srcImgPath, String distImgPath,
int width, int height) throws IOException {
File srcFile = new File(srcImgPath);
Image srcImg = ImageIO.read(srcFile);
BufferedImage buffImg = null;
buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
buffImg.getGraphics().drawImage(
srcImg.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0,
0, null);