liuyuqi-dellpc 7 years ago
commit
b3984cbdbf

+ 20 - 0
.classpath

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+/.settings
+/bin
+/target

+ 23 - 0
.project

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>ComposeName</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

File diff suppressed because it is too large
+ 0 - 0
data/chinese3500.txt


+ 0 - 0
data/result.txt


+ 64 - 0
pom.xml

@@ -0,0 +1,64 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>me.yoqi</groupId>
+	<artifactId>ComposeName</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<name>me.yoqi</name>
+	<build>
+		<sourceDirectory>src</sourceDirectory>
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.1</version>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<version>5.1.10</version>
+		</dependency>
+		<!-- Logback是由log4j创始人设计的又一个开源日志组件。logback当前分成三个模块:logback-core,logback- 
+			classic和logback-access。logback-core是其它两个模块的基础模块。logback-classic是log4j的一个 
+			改良版本。此外logback-classic完整实现SLF4J API使你可以很方便地更换成其它日志系统如log4j或JDK14 Logging。logback-access访问模块与Servlet容器集成提供通过Http来访问日志的功能。 -->
+		<dependency>
+			<groupId>ch.qos.logback</groupId>
+			<artifactId>logback-classic</artifactId>
+			<version>1.1.2</version>
+		</dependency>
+		<dependency>
+			<groupId>ch.qos.logback</groupId>
+			<artifactId>logback-access</artifactId>
+			<version>1.1.2</version>
+		</dependency>
+		<dependency>
+			<groupId>ch.qos.logback</groupId>
+			<artifactId>logback-core</artifactId>
+			<version>1.1.2</version>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<version>1.7.10</version>
+		</dependency>
+		<dependency>
+			<groupId>org.json</groupId>
+			<artifactId>json</artifactId>
+			<version>20140107</version>
+		</dependency>
+		<!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl -->
+		<dependency>
+			<groupId>net.sourceforge.jexcelapi</groupId>
+			<artifactId>jxl</artifactId>
+			<version>2.6.12</version>
+		</dependency>
+
+	</dependencies>
+	<description>目的,从chinese3500.txt里面,两两汉字组合。观察比较好的名字。</description>
+</project>

+ 1 - 0
readme.txt

@@ -0,0 +1 @@
+运行nohup  java -jar ComposeName.jar > ComposeName.log 2>&1 &

+ 40 - 0
src/me/yoqi/composename/Compose.java

@@ -0,0 +1,40 @@
+package me.yoqi.composename;
+
+import java.util.ArrayList;
+
+import qh.lqg.utils.Messages;
+import qh.lqg.utils.TextHelper;
+
+/**
+ * ClassName: Compose <br/>
+ * Function: 对3500个汉字两两组合. <br/>
+ * date: 2016年8月7日 上午11:51:28 <br/>
+ *
+ * @author liuyuqi
+ * @version
+ * @since JDK 1.7
+ */
+public class Compose {
+
+	public static void main(String args[]) throws Exception {
+
+		String dataUrl = Messages.getString("Compose.data");
+		String resultUrl = "data/result.txt";
+		String result = null;
+
+		TextHelper textHelper = new TextHelper();
+		ArrayList<String> allChinese = textHelper.readTextByWord(dataUrl);
+		ArrayList<String> allChineseName = textHelper.readTextByWord(dataUrl);
+		// 两两组合
+		for (int i = 0; i < 20; i++) {
+			for (int j = i + 1; j < allChinese.size() - 1; j++) {
+				allChineseName.add(allChinese.get(i) + allChinese.get(j));
+			}
+		}
+		// 打印输出
+		for (int k = 0; k < allChineseName.size(); k++) {
+			result += allChineseName.get(k);
+		}
+		textHelper.writeText(resultUrl, result);
+	}
+}

+ 32 - 0
src/qh/lqg/test/Employee.java

@@ -0,0 +1,32 @@
+package qh.lqg.test;
+
+public class Employee {
+	String name;
+	String sex;
+	int age;
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getSex() {
+		return sex;
+	}
+
+	public void setSex(String sex) {
+		this.sex = sex;
+	}
+
+	public int getAge() {
+		return age;
+	}
+
+	public void setAge(int i) {
+		this.age = i;
+	}
+
+}

+ 34 - 0
src/qh/lqg/test/TestHTTPSend.java

@@ -0,0 +1,34 @@
+package qh.lqg.test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import qh.lqg.utils.net.HTTPParam;
+import qh.lqg.utils.net.HTTPSend;
+
+public class TestHTTPSend {
+	private ArrayList<HTTPParam> param = new ArrayList<HTTPParam>();
+	private String result;
+	private String url;
+
+	public static void main(String[] args) throws IOException {
+		// TODO 自动生成的方法存根
+		TestHTTPSend testHTTPSend = new TestHTTPSend();
+		// testHTTPSend.testGet();
+		testHTTPSend.testPost();
+	}
+
+	public void testGet() throws IOException {
+		url = "http://www.cnblogs.com/zhuawang/archive/2012/12/08/2809380.html";
+		// HTTPParam httpParam = new HTTPParam();
+		// param.add(httpParam);
+		result = HTTPSend.sendGet(url, param);
+		System.out.println(result);
+	}
+
+	public void testPost() throws IOException {
+		String url = "http://www.cnblogs.com/zhuawang/archive/2012/12/08/2809380.html";
+		result = HTTPSend.sendPost(url, param);
+		System.out.println(result);
+	}
+}

+ 27 - 0
src/qh/lqg/test/TestHttpRequest.java

@@ -0,0 +1,27 @@
+package qh.lqg.test;
+
+import qh.lqg.utils.net.HttpRequest;
+
+public class TestHttpRequest {
+	public static void main(String[] args) {
+		// TODO 自动生成的方法存根
+		TestHttpRequest testHttpRequest = new TestHttpRequest();
+		testHttpRequest.testGet();
+	}
+
+	public void testGet() {
+		String url = "http://panda.www.net.cn/cgi-bin/check.cgi";
+		String param = "area_domain=baidu.com";
+		String result;
+		result = HttpRequest.sendGet(url, param);
+		System.out.println(result);
+	}
+
+	public void testPost() {
+		String url = "https://www.baidu.com";
+		String param = null;
+		String result;
+		result = HttpRequest.sendPost(url, param);
+		System.out.println(result);
+	}
+}

+ 33 - 0
src/qh/lqg/test/TestJdbc.java

@@ -0,0 +1,33 @@
+package qh.lqg.test;
+
+import java.io.UnsupportedEncodingException;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import qh.lqg.utils.Messages;
+import qh.lqg.utils.db.JdbcUtils;
+
+public class TestJdbc {
+
+	public static void main(String[] args) throws SQLException,
+			UnsupportedEncodingException {
+		// TODO 自动生成的方法存根
+		String userName, password, url;
+		userName = Messages.getString("TestJdbc.userName"); //$NON-NLS-1$
+		password = Messages.getString("TestJdbc.password"); //$NON-NLS-1$
+		url = Messages.getString("TestJdbc.url"); //$NON-NLS-1$
+		JdbcUtils jdbcUtils = new JdbcUtils();
+		jdbcUtils.setConnstr(userName, password, url);
+		jdbcUtils.getConnection();// 连接数据库
+		String sql = "UPDATE `tw_domain` SET  `description`=?, `chinese_description`=? WHERE (`domain_name`='baba.me')"; //$NON-NLS-1$
+		List<Object> params = new ArrayList<Object>();
+		params.add("90"); //$NON-NLS-1$
+		String str = "中文"; //$NON-NLS-1$
+		str = new String(str.getBytes(), "UTF8"); //$NON-NLS-1$
+		params.add("中文"); //$NON-NLS-1$
+		jdbcUtils.updateByPreparedStatement(sql, params);
+		System.out.println(sql);
+	}
+
+}

+ 40 - 0
src/qh/lqg/test/TestJson.java

@@ -0,0 +1,40 @@
+package qh.lqg.test;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import qh.lqg.utils.net.HttpRequest;
+
+public class TestJson {
+
+	public static void main(String[] args) {
+		// TODO 自动生成的方法存根
+		String resultJson = translateDomain("baidu");
+		JSONObject obj = new JSONObject(resultJson);
+		// JSONArray resultArray = new JSONArray(resultJson);
+		String chineseTranslation = "";
+		JSONArray array = (JSONArray) obj.getJSONArray("result").get(0);
+		for (int j = 0; j < array.length(); j++) {
+			chineseTranslation += ((JSONArray) array.get(j)).get(0).toString()
+					+ "-";
+		}
+		System.out.println(chineseTranslation);
+	}
+
+	/**
+	 * translateDomain:(拼音预测汉字,仿输入法结果). <br/>
+	 *
+	 * @author liuyuqi
+	 * @param input
+	 * @return
+	 * @since JDK 1.7
+	 */
+	public static String translateDomain(String input) {
+		String url = "http://olime.baidu.com/py";
+		return HttpRequest
+				.sendGet(
+						url,
+						"inputtype=py&bg=0&ed=5&result=hanzi&resultcoding=unicode&ch_en=0&clientinfo=web&version=1&input="
+								+ input);
+	}
+}

+ 73 - 0
src/qh/lqg/utils/ExcelOperater.java

@@ -0,0 +1,73 @@
+package qh.lqg.utils;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * ClassName: ExcelOperater <br/>
+ * Function: Excel操作类. <br/>
+ * date: 2016年8月7日 上午10:24:23 <br/>
+ *
+ * @author liuyuqi
+ * @version
+ * @since JDK 1.7
+ */
+public class ExcelOperater {
+	private InputStreamReader isr = null;
+	private BufferedReader br = null;
+
+	public ExcelOperater(String file) throws FileNotFoundException {
+		isr = new InputStreamReader(new FileInputStream(file));
+	}
+
+	/**
+	 * readCSVFile:(解析csv文件 到一个list中 每个单元个为一个String类型记录,每一行为一个list。
+	 * 再将所有的行放到一个总list中 ). <br/>
+	 *
+	 * @author liuyuqi
+	 * @return
+	 * @throws IOException
+	 * @since JDK 1.7
+	 */
+	public List<List<String>> readCSVFile() throws IOException {
+		br = new BufferedReader(isr);
+		String rec = null;// 一行
+		String str;// 一个单元格
+		List<List<String>> listFile = new ArrayList<List<String>>();
+		try {
+			// 读取一行
+			while ((rec = br.readLine()) != null) {
+				Pattern pCells = Pattern
+						.compile("(\"[^\"]*(\"{2})*[^\"]*\")*[^,]*,");
+				Matcher mCells = pCells.matcher(rec);
+				List<String> cells = new ArrayList<String>();// 每行记录一个list
+				// 读取每个单元格
+				while (mCells.find()) {
+					str = mCells.group();
+					str = str.replaceAll(
+							"(?sm)\"?([^\"]*(\"{2})*[^\"]*)\"?.*,", "$1");
+					str = str.replaceAll("(?sm)(\"(\"))", "$2");
+					cells.add(str);
+				}
+				listFile.add(cells);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			if (isr != null) {
+				isr.close();
+			}
+			if (br != null) {
+				br.close();
+			}
+		}
+		return listFile;
+	}
+}

+ 31 - 0
src/qh/lqg/utils/Messages.java

@@ -0,0 +1,31 @@
+package qh.lqg.utils;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * ClassName: Messages <br/>
+ * Function: 从messages.properties文件获取配置信息(getString). <br/>
+ * date: 2016年8月6日 上午1:21:52 <br/>
+ *
+ * @author liuyuqi
+ * @version
+ * @since JDK 1.7
+ */
+public class Messages {
+	private static final String BUNDLE_NAME = "qh.lqg.utils.messages"; //$NON-NLS-1$
+
+	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+			.getBundle(BUNDLE_NAME);
+
+	private Messages() {
+	}
+
+	public static String getString(String key) {
+		try {
+			return RESOURCE_BUNDLE.getString(key);
+		} catch (MissingResourceException e) {
+			return '!' + key + '!';
+		}
+	}
+}

+ 39 - 0
src/qh/lqg/utils/Strings2List.java

@@ -0,0 +1,39 @@
+package qh.lqg.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * ClassName: Strings2List <br/>
+ * Function: String[]和List转换工具类. <br/>
+ * date: 2016年8月7日 下午2:35:45 <br/>
+ *
+ * @author liuyuqi
+ * @version
+ * @since JDK 1.7
+ */
+public class Strings2List {
+	/**
+	 * ListToStrings:(List 转换为 String数组). <br/>
+	 *
+	 * @author liuyuqi
+	 * @param list
+	 * @return
+	 * @since JDK 1.7
+	 */
+	public static String[] listToStrings(ArrayList<String> list) {
+		return list.toArray(new String[list.size()]);
+	}
+
+	/**
+	 * StringsToList:(String[]转list). <br/>
+	 *
+	 * @author liuyuqi
+	 * @param arr
+	 * @return
+	 * @since JDK 1.7
+	 */
+	public static ArrayList<String> stringsToList(String[] arr) {
+		return (ArrayList<String>) Arrays.asList(arr);
+	}
+}

+ 58 - 0
src/qh/lqg/utils/TextHelper.java

@@ -0,0 +1,58 @@
+package qh.lqg.utils;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+
+public class TextHelper {
+	/**
+	 * readTxt:(读取txt文档(一行一行读取),返回String). <br/>
+	 *
+	 * @author liuyuqi
+	 * @param dataUrl
+	 *            文件路径(在项目根目录新建data文件夹放数据)
+	 * @return
+	 * @throws Exception
+	 * @since JDK 1.7
+	 */
+	public String readTextByLine(String dataUrl) throws Exception {
+		Reader reader = new InputStreamReader(new FileInputStream(dataUrl));
+		BufferedReader br = new BufferedReader(reader);
+		String data = "", line = null;
+		while ((line = br.readLine()) != null) {
+			data += line;
+		}
+		br.close();
+		return data;
+	}
+
+	public ArrayList<String> readTextByWord(String dataUrl) throws Exception {
+		ArrayList<String> list = new ArrayList<>();
+		Reader reader = new InputStreamReader(new FileInputStream(dataUrl));
+		BufferedReader br = new BufferedReader(reader);
+		String data = "", line = null;
+		while ((line = br.readLine()) != null) {
+			data += line;
+		}
+		br.close();
+		for (int i = 0; i < data.length(); i++) {
+			list.add(data.substring(i, i + 1));
+		}
+		return list;
+	}
+
+	public static void writeText(String fileName, String content) {
+		try {
+			// 打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
+			FileWriter writer = new FileWriter(fileName, true);
+			writer.write(content);
+			writer.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+}

+ 105 - 0
src/qh/lqg/utils/db/BatchInsert.java

@@ -0,0 +1,105 @@
+package qh.lqg.utils.db;
+
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+import com.mysql.jdbc.Connection;
+import com.mysql.jdbc.PreparedStatement;
+
+public class BatchInsert {
+
+	public void oneJdbcBatch(List<String> domain) throws SQLException,
+			ClassNotFoundException {
+		// 数据库连接驱动
+		Class.forName("com.mysql.jdbc.Driver");
+
+		// 连接数据库字符串
+		Connection con = (Connection) DriverManager.getConnection(
+				"jdbc:mysql://" + "localhost:3306/db_test", "lyq",
+				"123456");
+		// 关闭事务自动提交
+		con.setAutoCommit(false);
+		// 设置时间格式
+		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss:SS");
+		// 设置时区,中国上海
+		TimeZone t = sdf.getTimeZone();
+		t.setRawOffset(0);
+		sdf.setTimeZone(t);
+		// 获得当前时间,单位为毫秒。
+		// 计算公式:1秒1000毫秒,1分60秒,1时60分,1天24时。
+		Long startTime = System.currentTimeMillis();
+		// com.mysql.jdbc.PreparedStatement 数据库字符串构建类
+		PreparedStatement pst = (PreparedStatement) con
+				.prepareStatement("UPDATE `tw_domain` SET( `domain_name`) VALUES (?);");
+		for (int i = 0; i < domain.size(); i++) {
+			pst.setString(1, domain.get(i));// 设置第一个问号用i代替
+			// 把一个SQL命令加入命令列表
+			pst.addBatch();// mysql批处理函数
+		}
+		// 这样一个批处理命令就拼接完成
+		// 可以打印出来看看
+		// System.out.println(pst.toString());
+		// 执行批量更新
+		pst.executeBatch();
+		// 语句执行完毕,提交本事务
+		con.commit();
+
+		Long endTime = System.currentTimeMillis();
+		System.out.println("------一次插入30000条数据,最后提交命令情况-----");
+		System.out.println("用时:" + sdf.format(new Date(endTime - startTime)));
+
+		pst.close();
+		con.close();
+	}
+
+	public void muchJdbcBatch() throws ClassNotFoundException, SQLException {
+		// 数据库连接驱动
+		Class.forName("com.mysql.jdbc.Driver");
+
+		// 连接数据库字符串
+		Connection con = (Connection) DriverManager.getConnection(
+				"jdbc:mysql://" + "localhost:3306/db_test", "root", "123456");
+		// 关闭事务自动提交
+		con.setAutoCommit(false);
+		// 设置时间格式
+		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss:SS");
+		// 设置时区,中国上海
+		TimeZone t = sdf.getTimeZone();
+		t.setRawOffset(0);
+		sdf.setTimeZone(t);
+		// 获得当前时间,单位为毫秒。
+		// 计算公式:1秒1000毫秒,1分60秒,1时60分,1天24时。
+		Long startTime = System.currentTimeMillis();
+		// com.mysql.jdbc.PreparedStatement 数据库字符串构建类
+		PreparedStatement pst = (PreparedStatement) con
+				.prepareStatement("insert into jpa_person values (?,'中国')");
+		for (int j = 0; j < 300; j++) {
+			for (int i = 0; i < 100; i++) {
+				pst.setInt(1, i + j);// 设置第一个问号用i代替
+				// 把一个SQL命令加入命令列表
+				pst.addBatch();// mysql批处理函数
+			}
+			pst.executeBatch();
+			con.commit();
+		}
+
+		Long endTime = System.currentTimeMillis();
+		System.out.println("------一次插入100条数据,然后提交,如此重复300次情况-----");
+		System.out.println("用时:" + sdf.format(new Date(endTime - startTime)));
+
+		pst.close();
+		con.close();
+	}
+
+	public void oneJpaBatch() {
+
+	}
+
+	public void muchJpaBatch() {
+
+	}
+}

+ 232 - 0
src/qh/lqg/utils/db/JdbcUtils.java

@@ -0,0 +1,232 @@
+package qh.lqg.utils.db;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author lqg 数据库操作类,提供数据增,删,改,查基本操作。
+ */
+public class JdbcUtils {
+
+	// 数据库用户名
+	private String USERNAME = "lyq";
+	// 数据库密码
+	private String PASSWORD = "123456";
+	// 驱动信息
+	private String DRIVER = "com.mysql.jdbc.Driver";
+	// 数据库地址
+	// private static final String URL = "jdbc:mysql://172.16.90.108:3306/";
+	private String URL = "jdbc:mysql://localhost:3306/";
+	private Connection connection;
+	private PreparedStatement pstmt;
+	private ResultSet resultSet;
+	Logger logger = LoggerFactory.getLogger(JdbcUtils.class);
+
+	// 连接数据库
+	public JdbcUtils() {
+		// TODO Auto-generated constructor stub
+		try {
+			Class.forName(DRIVER);
+			logger.info("加载驱动成功!");
+		} catch (Exception e) {
+		}
+	}
+
+	/**
+	 * 这个函数主要是打印连接数据
+	 * 
+	 */
+	public void getConnStr() {
+		String str = "连接字符串为:\n" + "登录名:" + this.USERNAME + "\n密码:"
+				+ this.PASSWORD + "\n数据库地址:" + this.URL;
+		logger.info(str);
+	}
+
+	/**
+	 * 设置登录数据库账号,密码,连接什么数据库.set方法
+	 * 
+	 * @param _userName
+	 *            Mysql账号:root
+	 * @param _password
+	 *            密码:123456
+	 * @param _url
+	 *            登录数据库名:jdbc:mysql://localhost:3306/
+	 */
+	public void setConnstr(String _userName, String _password, String _url) {
+		this.USERNAME = _userName;
+		this.PASSWORD = _password;
+		this.URL = _url;
+	}
+
+	/**
+	 * 获得数据库的连接
+	 *
+	 * @return
+	 */
+	public Connection getConnection(String schemaName) {
+		String newURL = this.URL + schemaName;
+		logger.info(newURL);
+		try {
+			connection = DriverManager
+					.getConnection(newURL, USERNAME, PASSWORD);
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return connection;
+	}
+
+	public Connection getConnection() {
+		String newURL = this.URL;
+		logger.info(newURL);
+		try {
+			connection = DriverManager
+					.getConnection(newURL, USERNAME, PASSWORD);
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return connection;
+	}
+
+	/**
+	 * 增加、删除、改
+	 *
+	 * @param sql语句
+	 * @param params需要传递的变量
+	 *            ,比如表单提交的数据。
+	 * @return 这里返回值为成功和失败
+	 * @throws SQLException
+	 */
+	public boolean updateByPreparedStatement(String sql, List<Object> params)
+			throws SQLException {
+		boolean flag = false;
+		int result = -1;
+		pstmt = connection.prepareStatement(sql);
+		int index = 1;
+		if (params != null && !params.isEmpty()) {
+			for (int i = 0; i < params.size(); i++) {
+				pstmt.setObject(index++, params.get(i));
+			}
+		}
+
+		// System.out.println(pstmt.getMetaData().toString());
+		// System.out.println(pstmt.toString());
+		logger.info(pstmt.toString());
+		result = pstmt.executeUpdate();
+		flag = result > 0 ? true : false;
+		return flag;
+	}
+
+	/**
+	 * 查询单条记录
+	 *
+	 * @param sql
+	 * @param params
+	 * @return
+	 * @throws SQLException
+	 */
+	public Map<String, Object> findSimpleResult(String sql, List<Object> params)
+			throws SQLException {
+		Map<String, Object> map = new HashMap<String, Object>();
+		int index = 1;
+		pstmt = connection.prepareStatement(sql);
+		if (params != null && !params.isEmpty()) {
+			for (int i = 0; i < params.size(); i++) {
+				pstmt.setObject(index++, params.get(i));
+			}
+		}
+		resultSet = pstmt.executeQuery();// 返回查询结果
+		ResultSetMetaData metaData = resultSet.getMetaData();
+		int col_len = metaData.getColumnCount();
+		while (resultSet.next()) {
+			for (int i = 0; i < col_len; i++) {
+				String cols_name = metaData.getColumnName(i + 1);
+				Object cols_value = resultSet.getObject(cols_name);
+				if (cols_value == null) {
+					cols_value = "";
+				}
+				map.put(cols_name, cols_value);
+			}
+		}
+		return map;
+	}
+
+	/**
+	 * 查询多条记录
+	 *
+	 * @param sql语句
+	 * @param params
+	 *            (不管,设为null)
+	 * @return
+	 * @throws SQLException
+	 */
+	public List<Map<String, Object>> findModeResult(String sql,
+			List<Object> params) throws SQLException {
+		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
+		int index = 1;
+		pstmt = connection.prepareStatement(sql);
+		if (params != null && !params.isEmpty()) {
+			for (int i = 0; i < params.size(); i++) {
+				pstmt.setObject(index++, params.get(i));
+			}
+		}
+		// 得到数据集
+		resultSet = pstmt.executeQuery();
+		// 从数据集中提取数据
+		ResultSetMetaData metaData = resultSet.getMetaData();
+		// 计算有多少行数据
+		int cols_len = metaData.getColumnCount();
+		// 把所有数据转换成List格式
+		while (resultSet.next()) {
+			Map<String, Object> map = new HashMap<String, Object>();
+			for (int i = 0; i < cols_len; i++) {
+				String cols_name = metaData.getColumnName(i + 1);
+				Object cols_value = resultSet.getObject(cols_name);
+				if (cols_value == null) {
+					cols_value = "";
+				}
+				map.put(cols_name, cols_value);
+			}
+			list.add(map);
+		}
+		return list;
+	}
+
+	/**
+	 * 释放数据库连接
+	 */
+	public void releaseConn() {
+		if (resultSet != null) {
+			try {
+				resultSet.close();
+			} catch (SQLException e) {
+//				e.printStackTrace();
+				logger.error("releaseConn error:" + e.getMessage());
+			}
+		}
+
+	}
+	public void closeConn(){
+		if(connection!=null){
+			try {
+				connection.close();
+			} catch (SQLException e) {
+				// TODO 自动生成的 catch 块
+//				e.printStackTrace();
+				logger.error("closeConn error:" + e.getMessage());
+			}
+		}
+	}
+}

+ 1 - 0
src/qh/lqg/utils/messages.properties

@@ -0,0 +1 @@
+Compose.data=data/chinese3500.txt

+ 33 - 0
src/qh/lqg/utils/net/HTTPParam.java

@@ -0,0 +1,33 @@
+package qh.lqg.utils.net;
+
+public class HTTPParam {
+	// 请求参数
+	private String key;
+	// 参数值
+	private String value;
+
+	public HTTPParam() {
+
+	}
+
+	public HTTPParam(String key, String value) {
+		this.key = key;
+		this.value = value;
+	}
+
+	public String getKey() {
+		return key;
+	}
+
+	public void setKey(String key) {
+		this.key = key;
+	}
+
+	public String getValue() {
+		return value;
+	}
+
+	public void setValue(String value) {
+		this.value = value;
+	}
+}

+ 133 - 0
src/qh/lqg/utils/net/HTTPSend.java

@@ -0,0 +1,133 @@
+package qh.lqg.utils.net;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.List;
+
+/**
+ * Created by XdaTk on 2014/12/21.
+ * <p/>
+ * HTTP请求工具类
+ */
+public class HTTPSend {
+	/**
+	 * 发送get请求
+	 *
+	 * @param url
+	 *            请求地址
+	 * @param list
+	 *            请求参数
+	 *
+	 * @return 请求结果
+	 *
+	 * @throws IOException
+	 */
+	public static String sendGet(String url, List<HTTPParam> list)
+			throws IOException {
+		StringBuffer buffer = new StringBuffer(); // 用来拼接参数
+		StringBuffer result = new StringBuffer(); // 用来接受返回值
+		URL httpUrl = null; // HTTP URL类 用这个类来创建连接
+		URLConnection connection = null; // 创建的http连接
+		BufferedReader bufferedReader = null; // 接受连接受的参数
+		// 如果存在参数,我们才需要拼接参数 类似于 localhost/index.html?a=a&b=b
+		if (list.size() > 0) {
+			for (int i = 0; i < list.size(); i++) {
+				buffer.append(list.get(i).getKey())
+						.append("=")
+						.append(URLEncoder.encode(list.get(i).getValue(),
+								"utf-8"));
+				// 如果不是最后一个参数,不需要添加&
+				if ((i + 1) < list.size()) {
+					buffer.append("&");
+				}
+			}
+			url = url + "?" + buffer.toString();
+		}
+		// 创建URL
+		httpUrl = new URL(url);
+		// 建立连接
+		connection = httpUrl.openConnection();
+		connection
+				.setRequestProperty("accept",
+						"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+		connection.setRequestProperty("connection", "keep-alive");
+		connection
+				.setRequestProperty("user-agent",
+						"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0");
+		connection.connect();
+		// 接受连接返回参数
+		bufferedReader = new BufferedReader(new InputStreamReader(
+				connection.getInputStream()));
+		String line;
+		while ((line = bufferedReader.readLine()) != null) {
+			result.append(line);
+		}
+		bufferedReader.close();
+		return result.toString();
+	}
+
+	/**
+	 * 发送Post请求
+	 *
+	 * @param url
+	 *            请求地址
+	 * @param list
+	 *            请求参数
+	 *
+	 * @return 请求结果
+	 *
+	 * @throws IOException
+	 */
+	public static String sendPost(String url, List<HTTPParam> list)
+			throws IOException {
+		StringBuffer buffer = new StringBuffer(); // 用来拼接参数
+		StringBuffer result = new StringBuffer(); // 用来接受返回值
+		URL httpUrl = null; // HTTP URL类 用这个类来创建连接
+		URLConnection connection = null; // 创建的http连接
+		PrintWriter printWriter = null;
+		BufferedReader bufferedReader; // 接受连接受的参数
+		// 创建URL
+		httpUrl = new URL(url);
+		// 建立连接
+		connection = httpUrl.openConnection();
+		connection
+				.setRequestProperty("accept",
+						"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+		connection.setRequestProperty("connection", "keep-alive");
+		connection
+				.setRequestProperty("user-agent",
+						"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0");
+		connection.setDoOutput(true);
+		connection.setDoInput(true);
+		printWriter = new PrintWriter(connection.getOutputStream());
+		if (list.size() > 0) {
+			for (int i = 0; i < list.size(); i++) {
+				buffer.append(list.get(i).getKey())
+						.append("=")
+						.append(URLEncoder.encode(list.get(i).getValue(),
+								"utf-8"));
+				// 如果不是最后一个参数,不需要添加&
+				if ((i + 1) < list.size()) {
+					buffer.append("&");
+				}
+			}
+		}
+		printWriter.print(buffer.toString());
+		printWriter.flush();
+		connection.connect();
+		// 接受连接返回参数
+		bufferedReader = new BufferedReader(new InputStreamReader(
+				connection.getInputStream()));
+		String line;
+		while ((line = bufferedReader.readLine()) != null) {
+			result.append(line);
+		}
+		bufferedReader.close();
+		return result.toString();
+	}
+}

+ 124 - 0
src/qh/lqg/utils/net/HttpRequest.java

@@ -0,0 +1,124 @@
+package qh.lqg.utils.net;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.List;
+import java.util.Map;
+
+public class HttpRequest {
+	/**
+	 * 向指定URL发送GET方法的请求
+	 * 
+	 * @param url
+	 *            发送请求的URL
+	 * @param param
+	 *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
+	 * @return URL 所代表远程资源的响应结果
+	 */
+	public static String sendGet(String url, String param) {
+		String result = "";
+		BufferedReader in = null;
+		try {
+			String urlNameString = url + "?" + param;
+			URL realUrl = new URL(urlNameString);
+			// 打开和URL之间的连接
+			URLConnection connection = realUrl.openConnection();
+			// 设置通用的请求属性
+			connection.setRequestProperty("accept", "*/*");
+			connection.setRequestProperty("connection", "Keep-Alive");
+			connection.setRequestProperty("user-agent",
+					"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+			// 建立实际的连接
+			connection.connect();
+			// 获取所有响应头字段
+			Map<String, List<String>> map = connection.getHeaderFields();
+			// 遍历所有的响应头字段
+			for (String key : map.keySet()) {
+				System.out.println(key + "--->" + map.get(key));
+			}
+			// 定义 BufferedReader输入流来读取URL的响应
+			in = new BufferedReader(new InputStreamReader(
+					connection.getInputStream()));
+			String line;
+			while ((line = in.readLine()) != null) {
+				result += line;
+			}
+		} catch (Exception e) {
+			System.out.println("发送GET请求出现异常!" + e);
+			e.printStackTrace();
+		}
+		// 使用finally块来关闭输入流
+		finally {
+			try {
+				if (in != null) {
+					in.close();
+				}
+			} catch (Exception e2) {
+				e2.printStackTrace();
+			}
+		}
+		return result;
+	}
+
+	/**
+	 * 向指定 URL 发送POST方法的请求
+	 * 
+	 * @param url
+	 *            发送请求的 URL
+	 * @param param
+	 *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
+	 * @return 所代表远程资源的响应结果
+	 */
+	public static String sendPost(String url, String param) {
+		PrintWriter out = null;
+		BufferedReader in = null;
+		String result = "";
+		try {
+			URL realUrl = new URL(url);
+			// 打开和URL之间的连接
+			URLConnection conn = realUrl.openConnection();
+			// 设置通用的请求属性
+			conn.setRequestProperty("accept", "*/*");
+			conn.setRequestProperty("connection", "Keep-Alive");
+			conn.setRequestProperty("user-agent",
+					"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+			// 发送POST请求必须设置如下两行
+			conn.setDoOutput(true);
+			conn.setDoInput(true);
+			// 获取URLConnection对象对应的输出流
+			out = new PrintWriter(conn.getOutputStream());
+			// 发送请求参数
+			out.print(param);
+			// flush输出流的缓冲
+			out.flush();
+			// 定义BufferedReader输入流来读取URL的响应
+			in = new BufferedReader(
+					new InputStreamReader(conn.getInputStream()));
+			String line;
+			while ((line = in.readLine()) != null) {
+				result += line;
+			}
+		} catch (Exception e) {
+			System.out.println("发送 POST 请求出现异常!" + e);
+			e.printStackTrace();
+		}
+		// 使用finally块来关闭输出流、输入流
+		finally {
+			try {
+				if (out != null) {
+					out.close();
+				}
+				if (in != null) {
+					in.close();
+				}
+			} catch (IOException ex) {
+				ex.printStackTrace();
+			}
+		}
+		return result;
+	}
+}

Some files were not shown because too many files changed in this diff