`
newleague
  • 浏览: 1513754 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

12334445555

    博客分类:
  • http
阅读更多
package test;

/* 
* Created on 2010-08-16 
*  注意:执行之前,需记录tb_trouble_code_desc,tb_trouble_code记录数,最大的ID,另外将序列值调整到最大的ID

*/

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Arrays;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.log4j.Logger;

/**
* @author madp
* 用于抓取canobd2网站上故障码数据
*/
public class GrabDTCByHttpClient extends Thread{
private static final Logger log = Logger.getLogger(GrabDTCByHttpClient.class);
String [] makeArray = null;

public GrabDTCByHttpClient(){}

public GrabDTCByHttpClient(String [] makes){
makeArray = makes;
}

public static void main(String[] args) {
runMain();
}

public static void runMain(){
String [] makes = {
"Infiniti",
"Isuzu",
"Jaguar",
"Jeep",
"Kia",
"Land Rover",
"Lexus",
"Lincoln",
"Maybach",
"Mazda",
"Mercedes-Benz",
"Mercury",
"Merkur",
"Mitsubishi",
"Nissan",
"Oldsmobile",
"Plymouth",
"Pontiac",
"Porsche",
"Saab",
"Saturn",
"Scion",
"Sterling",
"Subaru",
"Suzuki",
"Toyota",
"Volkswagen"};
String [] bb = new String[1];

/** 利用多线程,开启27个线程 **/
for(int i=0;i<27;i++){
System.arraycopy(makes, i, bb, 0, 1);
for(int j=0;j<1;j++){
System.out.println("--bb-->"+bb[j]);
}
Thread thread = new GrabDTCByHttpClient(bb);
thread.start();
}
}

/**
* 的到Http请求结果
*
* @param url请求地址
* @param parms请求参数
* @return
*/
public byte[] getBody(String url, Map parms) {
byte[] body = null;
// 构造HttpClient的实例
HttpClient httpClient = new HttpClient();
// 创建post方法的实例
PostMethod postMethod = new PostMethod(url);
// 填入各个表单域的值
NameValuePair[] data = new NameValuePair[parms.keySet().size()];
Iterator it = parms.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
data[i] = new NameValuePair(key.toString(), value.toString());
i++;
}

// 将表单的值放入postMethod中
postMethod.setRequestBody(data);
try {
// 执行postMethod
int statusCode = httpClient.executeMethod(postMethod); // HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发
// 301或者302
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY
|| statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
// 从头中取出转向的地址
Header locationHeader = postMethod
.getResponseHeader("location");
String location = null;
if (locationHeader != null) {
location = locationHeader.getValue();
System.out
.println("The page was redirected to:" + location);
} else {
System.err.println("Location field value is null.");
}
}
body = postMethod.getResponseBody();

} catch (Exception e) {
e.printStackTrace();
System.out.println("--getBody出现问题--");
log.info("--getBody出现问题--"+e);
runMain();
}
return body;
}

public void run(){
runGrab(makeArray);
}

public  void runGrab(String [] makes){
synchronized(makes){
File file11 = new File("d://commonMakes.txt");
FileOutputStream fos11 = null;
try {
fos11 = new FileOutputStream(file11);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
PrintWriter pw11 = new PrintWriter(fos11);
String url = "http://www.canobd2.com/DtcLibrary/default.aspx";
/** 数组:所有车系 注意:Land Rover车系单独处理 别忘记了 **/
/** 如果执行中断,将当前的车系独立出来,将没有执行的故障码执行完后再列出以后的车系,并且将FOR循环里变量还原为初始状态,即从0-10迭代**/
// String[] makes = { /** 检查车系是否完整 **/
// "Hyundai" };

/**
        "Acura",
"Alfa Romeo",
"Asuna",
"Audi",
"BMW",
"Buick",
"Cadillac",
"Chevrolet",
"Chrysler",
"Daewoo",
"Dodge",
"Eagle",
"Ford",
"Geo",
"GMC",
"Honda",
"Hyundai",
"Infiniti",
"Isuzu",
"Jaguar",
"Jeep",
"Kia",
"Land Rover",
"Lexus",
"Lincoln",
"Maybach",
"Mazda",
"Mercedes-Benz",
"Mercury",
"Merkur",
"Mitsubishi",
"Nissan",
"Oldsmobile",
"Plymouth",
"Pontiac",
"Porsche",
"Saab",
"Saturn",
"Scion",
"Sterling",
"Subaru",
"Suzuki",
"Toyota",
"Volkswagen"
*/
/** 将Land Rover车系单独出来处理,因为与crecorder的车系名称LANDROVER有区别 **/
Long startTime = new Date().getTime();
/** troublecodes:通用、专用故障码 **/
List<String> troublecodes = new ArrayList<String>();
/** finalTroublecodes:需抓取数据的故障码 **/
List<String> finalTroublecodes = new ArrayList<String>();
String strP0 = null;
String strP1 = null;
String strP2 = null;
String strP3 = null;
String str1 = null;
for(int i=1;i<10;i++){
for(int j=0;j<10;j++){
for(int k=0;k<10;k++){
str1 = String.valueOf(i)+String.valueOf(j)+String.valueOf(k);
strP0 = "P0"+ str1;
strP2 = "P2"+ str1;
if(Integer.parseInt(str1.substring(0, 1))>=4){
strP3 = "P3"+ str1;
}
if(strP0!=null){
troublecodes.add(strP0);
}
if(strP2!=null){
troublecodes.add(strP2);
}
if(strP3!=null){
troublecodes.add(strP3);
}
}
}
}
/** 获得数据库连接 **/
Connection connection = null;
try {
connection = getConnection();
} catch (ClassNotFoundException e3) {
e3.printStackTrace();
System.out.println("--getConnection出现问题--");
new GrabDTCByHttpClient().start();
} catch (SQLException e) {
e.printStackTrace();
System.out.println("--getConnection出现问题--");
new GrabDTCByHttpClient().start();
}
File file1 = new File("d://commonRecord.txt");
FileOutputStream fos = null;


try {
fos = new FileOutputStream(file1);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
PrintWriter pw = new PrintWriter(fos);

/** 分为两种情况 **/
/** 1、通用情况 **/
String commonTroubleCodeSql = "select count(1) from tb_trouble_code_desc  where trouble_code = ?" +
" and lan_id = 15";
Long count = null;
System.out.println("---通用故障码总数量-->"+troublecodes.size());
print(pw,"---通用故障码总数量-->"+troublecodes.size());
for(int i=0;i<troublecodes.size();i++){
/** 查看数据库中是否有记录 **/
count = getCount(connection,troublecodes.get(i),null,commonTroubleCodeSql);
String str = "--通用:数据库中记录数-->"+count+"->"+troublecodes.get(i);
System.out.println(str);
print(pw,str);

if(count==0){ /** 没有记录时,收集故障码 **/
System.out.println("--通用:待插入的故障码-->"+troublecodes.get(i));
print(pw,"--通用:待插入的故障码-->"+troublecodes.get(i));
finalTroublecodes.add(troublecodes.get(i));
}
}
System.out.println("---通用:待抓取并插入的故障码总数量-->"+finalTroublecodes.size()); /** 此数据应该与共插入的条数匹配 **/
print(pw,"---通用:待抓取并插入的故障码总数量-->"+finalTroublecodes.size());
/** 通用情况,所有车系对应统一的故障码描述,所以只取一个车系**/
String subMake [] = new String[1];
System.arraycopy(makes, 0, subMake, 0, 1);
for(String sr:makes){
print(pw11, sr);/** 打印每个开启的线程里的车系 **/
}

for(int i=0;i<subMake.length;i++){
System.out.println(subMake[i]);
}
grabAndInsert(pw,subMake,finalTroublecodes,url,connection);
print(pw,"--通用结束,开始专用情况--");
if(pw!=null){
pw.close();
pw = null;
}
try{
if(fos!=null){
fos.close();
fos = null;
}
}catch(Exception e){
e.printStackTrace();
}
if(pw11!=null){
pw11.close();
pw11 = null;
}
try{
if(fos11!=null){
fos11.close();
fos11 = null;
}
}catch(Exception e){
e.printStackTrace();
}
System.out.println("--通用结束,开始专用情况--");
System.out.println("************************");

/** 2、专用故障码情况 **/
troublecodes.clear();/** 清空 **/
finalTroublecodes.clear();/** 清空 **/
for(int i=1;i<10;i++){
for(int j=0;j<10;j++){
for(int k=0;k<10;k++){
str1 = String.valueOf(i)+String.valueOf(j)+String.valueOf(k);
strP1 = "P1"+ str1;
if(Integer.parseInt(str1.substring(0, 1))<4&&Integer.parseInt(str1.substring(0, 1))>=0){
strP3 = "P3"+ str1;
}
if(strP1!=null){
troublecodes.add(strP1);
}
if(strP3!=null){
troublecodes.add(strP3);
}
}
}
}
File file2 = new File("d://singleRecord.txt");
FileOutputStream fos2 = null;
try {
fos2 = new FileOutputStream(file2);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PrintWriter pw2 = new PrintWriter(fos2);
System.out.println("---专用故障码总数量-->"+troublecodes.size());
print(pw2,"---专用故障码总数量-->"+troublecodes.size());
String isExistSql = "select count(1) from tb_trouble_code_desc  where trouble_code = ?" +
" and lan_id = 15 and models = ?";
for(int j=0;j<makes.length;j++){
for(int i=0;i<troublecodes.size();i++){
count = getCount(connection,troublecodes.get(i),makes[j],isExistSql);
System.out.println("--专用:数据库中记录数-->"+count);
print(pw2,"--专用:数据库中记录数-->"+count);
if(count==0){/** 数据库中无记录,列出有哪些troublecode,然后统一抓取后插入数据库 **/
System.out.println("--专用:待插入的故障码-->"+troublecodes.get(i)+"->"+makes[j]);
print(pw2,"--专用:待插入的故障码-->"+troublecodes.get(i)+"->"+makes[j]);
finalTroublecodes.add(troublecodes.get(i));
}
}
}
System.out.println("---专用:待抓取并插入的故障码总数量-->"+finalTroublecodes.size()); /** 此数据应该与共插入的条数匹配 **/
print(pw2,"---专用:待抓取并插入的故障码总数量-->"+finalTroublecodes.size());
grabAndInsert(pw2,makes,finalTroublecodes,url,connection);
if(pw2!=null){
pw2.close();
pw2 = null;
}
try{
if(fos2!=null){
fos2.close();
fos2 = null;
}
}catch(Exception e){
e.printStackTrace();
}
/** 关闭数据库链接 **/
closeConnection(connection);
Long endTime = new Date().getTime();
System.out.println("---------success----->"+(endTime-startTime)); /** 抓取数据及插入数据库,执行成功 **/

}
public static Long getCount(Connection connection,String troubleCode,String model,String sql){ /** 获取记录数 **/
PreparedStatement pr = null;
ResultSet rs = null;
Long count = null;
try {
pr = connection.prepareStatement(sql);

if(model==null){/** 判断通用故障码 如:P0开头等**/
pr.setString(1, troubleCode);
}else{
pr.setString(1, troubleCode);
pr.setString(2, model);
}

rs = pr.executeQuery();
if(rs.next()){
count = rs.getLong(1);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(rs!=null){
rs.close();
rs = null;
}
if(pr!=null){
pr.close();
pr = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return count;
}

/** 打印输出到文件 **/
public void print(PrintWriter pw,String str){
try{
pw.println(str);
pw.flush();
}catch(Exception e){
e.printStackTrace();
}
}

/** 抓取数据后插入数据库 **/
public void grabAndInsert(PrintWriter pw,String[] makes,List<String> troublecodes,String url,Connection connection){
Map parms1 = new HashMap();
GrabDTCByHttpClient client = new GrabDTCByHttpClient();
parms1.put("submitButton", "Submit");
parms1.put("__EVENTARGUMENT", "");
parms1.put("__EVENTTARGET", "");
parms1.put("__sx", "0");
parms1
.put(
"__VIEWSTATE",
"/wEPDwULLTE5MzcxNjE1MzkPFgQeDl9fUHJldmlvdXNQYWdlZR4LX19SZXR1cm5VcmwFGC9EdGNMaWJyYXJ5L2RlZmF1bHQuYXNweBYCAgEPZBYIZg9kFgZmDxYCHgVzdHlsZQUNZGlzcGxheTpub25lO2QCAg8WAh4HVmlzaWJsZWdkAgMPFgIfA2hkAgUPEA8WAh4LXyFEYXRhQm91bmRnZBAVLQ5TZWxlY3QgTWFrZS4uLgVBY3VyYQpBbGZhIFJvbWVvBUFzdW5hBEF1ZGkDQk1XBUJ1aWNrCENhZGlsbGFjCUNoZXZyb2xldAhDaHJ5c2xlcgZEYWV3b28FRG9kZ2UFRWFnbGUERm9yZANHZW8DR01DBUhvbmRhB0h5dW5kYWkISW5maW5pdGkFSXN1enUGSmFndWFyBEplZXADS2lhCkxhbmQgUm92ZXIFTGV4dXMHTGluY29sbgdNYXliYWNoBU1hemRhDU1lcmNlZGVzLUJlbnoHTWVyY3VyeQZNZXJrdXIKTWl0c3ViaXNoaQZOaXNzYW4KT2xkc21vYmlsZQhQbHltb3V0aAdQb250aWFjB1BvcnNjaGUEU2FhYgZTYXR1cm4FU2Npb24IU3RlcmxpbmcGU3ViYXJ1BlN1enVraQZUb3lvdGEKVm9sa3N3YWdlbhUtAAVBY3VyYQpBbGZhIFJvbWVvBUFzdW5hBEF1ZGkDQk1XBUJ1aWNrCENhZGlsbGFjCUNoZXZyb2xldAhDaHJ5c2xlcgZEYWV3b28FRG9kZ2UFRWFnbGUERm9yZANHZW8DR01DBUhvbmRhB0h5dW5kYWkISW5maW5pdGkFSXN1enUGSmFndWFyBEplZXADS2lhCkxhbmQgUm92ZXIFTGV4dXMHTGluY29sbgdNYXliYWNoBU1hemRhDU1lcmNlZGVzLUJlbnoHTWVyY3VyeQZNZXJrdXIKTWl0c3ViaXNoaQZOaXNzYW4KT2xkc21vYmlsZQhQbHltb3V0aAdQb250aWFjB1BvcnNjaGUEU2FhYgZTYXR1cm4FU2Npb24IU3RlcmxpbmcGU3ViYXJ1BlN1enVraQZUb3lvdGEKVm9sa3N3YWdlbhQrAy1nZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dkZAIIDxYCHwNnFgZmDw8WAh4EVGV4dAUFUDAwMDFkZAIBDw8WAh8FBQNCTVdkZAICDw8WAh8FBSxGdWVsIFZvbHVtZSBSZWd1bGF0b3IgQ29udHJvbCBDaXJjdWl0IC8gT3BlbmRkAgkPFgIfA2hkZOkD5Ngxd3cE1BXKSzs9IYasdy+1");
parms1.put("__sy", "102");
int ii = 0;
int jj = 0;
for (int i = 0; i < makes.length; i++) { //45
parms1.put("vehicleMake", makes[i]);
for (int j = 0; j < troublecodes.size(); j++) { //4000
parms1.put("dtc", troublecodes.get(j));
// 根据车系、故障码查出描述
String result2 = null;
try {
result2 = new String(client.getBody(url, parms1),"utf-8");
} catch (UnsupportedEncodingException e2) {
System.out.println("-- 字符串转换错误 --");
e2.printStackTrace();
}
//String [] str = result2.split("descriptionLabel"+"\\p{Punct}\\p{Punct}"); /** 判断返回的字符串中是否包含descriptionLabel"> **/
String regex = "<span id=\"descriptionLabel\">([^<]*)</span>";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(result2);
if(matcher.find()){ /** 若length>1,一定包含 **/
String str = matcher.group(1);
/**
* 获得的数据:
* 车系:makes[i]
* 故障码:troublecodes.get(j)
* 描述:str[1]
*/
if(makes[i] == "Land Rover"){
makes[i] = "LANDROVER";
}
System.out.println("-- 插入的数据 -->"+makes[i].toUpperCase()+" -> "+troublecodes.get(j)+" -> "+str);
print(pw,"-- 插入的数据 -->"+makes[i].toUpperCase()+" -> "+troublecodes.get(j)+" -> "+str);
preInsertData(connection,makes[i].toUpperCase(),troublecodes.get(j),str);
ii++;
}else{ /** 没有找到对应的数据 **/
System.out.println("--没有抓取到数据-->"+makes[i]+"->"+troublecodes.get(j));
print(pw, "--没有抓取到数据-->"+makes[i]+"->"+troublecodes.get(j));
jj++;
//System.out.println("-------------***--str--22-----"+makes[i]+"@"+troublecodes.get(j)+"@"+"Sorry, we were unable to find that code.");
//String ret = makes[i]+"@"+troublecodes.get(j)+"@"+"Sorry, we were unable to find that code.";
//pw.println(ret);
//pw.flush();
}
}
}

System.out.println("--共插入数据库的数据量-->"+ii);
System.out.println("--没有抓取到数据的总量-->"+jj);
print(pw, "--共插入数据库的数据量-->"+ii);
print(pw, "--没有抓取到数据的总量-->"+jj);

}

/** 获得连接 *
* @throws ClassNotFoundException
* @throws SQLException */
public static Connection getConnection() throws ClassNotFoundException, SQLException{
String driverName = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@192.168.17.96:1521:TX431";
String user = "crecorder";
String password = "crecorder";
Connection conn = null;
try {
Class.forName(driverName);
conn = DriverManager.getConnection(url, user, password);
System.out.println("-- 获取数据库链接成功 --");
}catch(ClassNotFoundException e){
System.out.println("-- 获取数据库链接失败,驱动不存在 --");
e.printStackTrace();
throw e;
}catch (SQLException e) {
System.out.println("-- 获取数据库链接失败 --");
e.printStackTrace();
throw e;
}
return conn;
}


/** 准备插入数据 **/
public static void preInsertData(Connection connection,String make,String troubleCode,String desc){
System.out.println("-- 开始插入数据 --");
/** 根据故障码,获得父键PID **/
Long pid = getPidByTroubleCode(connection,troubleCode);
if(pid!=null){ /** 父键存在 **/
insertData(connection,pid,troubleCode,desc,make);
}else{ /** 父键不存在,插入故障码到父表,获得父键PID **/
pid = getPidByInsertTroubleCode(connection,troubleCode);
insertData(connection,pid,troubleCode,desc,make);
}
}

/** 插入数据 **/
public static void insertData(Connection connection,Long pid,String troubleCode,String desc,String make){
String sql = "insert into tb_trouble_code_desc values(trouble_code_desc_seq.nextval,?,?,'','',15,?,?,'','')";
// String string = "insert into tb_trouble_code_desc values(trouble_code_desc_seq.nextval,"+pid+","+troubleCode+",'','',15,"+desc+","+make+",'','')";
// System.out.println("-->"+string);
/**
*  ID           NUMBER(15)    
PID          NUMBER(15)    
TROUBLE_CODE VARCHAR2(512) 
DESCRIPTION  VARCHAR2(1536)
PDF_PATH     VARCHAR2(250) 
LAN_ID       NUMBER(15)    
BRIEF_DESC   VARCHAR2(1024)
MODELS       VARCHAR2(256) 
YEAR         NUMBER(4)     
TYPE         NUMBER(1)   
*/
PreparedStatement pstmt = null;
try {
pstmt = connection.prepareStatement(sql);
pstmt.setLong(1, pid);
pstmt.setString(2, troubleCode);
pstmt.setString(3, desc);
pstmt.setString(4, make);
pstmt.execute();
System.out.println("-- 插入数据成功 --");
} catch (SQLException e) {
System.out.println("-- 插入数据失败 --");
e.printStackTrace();
}
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}

}
/** 通过故障码查询父键PID**/
public static Long getPidByTroubleCode(Connection connection,String troubleCode){
Long pid = null;
/** 查询数据库,获得父键PID**/
String pidSql = "select id from tb_trouble_code t where t.trouble_code = ?";
ResultSet rs = null;
PreparedStatement pStatement = null;
try{
pStatement = connection.prepareStatement(pidSql);
pStatement.setString(1, troubleCode);
rs = pStatement.executeQuery();
while(rs.next()){
pid = rs.getLong("id"); /** 一条记录 **/
}
//System.out.println("-- 获取父键PID成功 -->"+pid);
}catch(SQLException e){
System.out.println("-- 获取父键PID失败 --");
e.printStackTrace();
}
try {
rs.close();
pStatement.close();
} catch (SQLException e) {
e.printStackTrace();
}

return pid;
}

/** 插入故障码并返回主键PID**/
public static Long getPidByInsertTroubleCode(Connection connection,String troubleCode){
Long pid = null;
/** 为了获得主表的PID,先取sequence,再往主表插入记录。**/
String sequenceSql = "select trouble_code_seq.nextval pid from dual ";
try {
PreparedStatement pr = connection.prepareStatement(sequenceSql);
ResultSet rs = pr.executeQuery();
if(rs.next()){
pid = rs.getLong("pid");
}
System.out.println("-- 获取sequence,返回主键PID成功-->"+pid);
rs.close();
pr.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}




String troubleCodeSql = "insert into tb_trouble_code values(?,?,'','madp')";

/**
*  ID           NUMBER(15)   
TROUBLE_CODE VARCHAR2(512)
ENTRY_TIME   DATE         
CREATOR      VARCHAR2(60)
*/
try {
PreparedStatement prstmt = connection.prepareStatement(troubleCodeSql, Statement.RETURN_GENERATED_KEYS);
prstmt.setLong(1, pid);
prstmt.setString(2, troubleCode);
prstmt.execute();
// ResultSet rSet = prstmt.getGeneratedKeys();
// while(rSet.next()){
// System.out.println("----"+rSet.getString(1));
// //pid = Integer.valueOf(rSet.getInt(1)).longValue();
// }
System.out.println("-- 插入故障码成功--");
//rSet.close();
prstmt.close();
} catch (SQLException e) {
System.out.println("-- 插入故障码并返回主键PID失败--");
e.printStackTrace();
}
return pid;
}

/** 关闭数据库连接 **/
public static void closeConnection(Connection conn){
try{
if(!conn.isClosed()){
conn.close();
}
}catch(SQLException e){
e.printStackTrace();
}
}

/** 插入数据库中没有的车系 表:tb_car_desc *
* @throws ClassNotFoundException
* @throws SQLException */
public static void insertMake(String make) throws ClassNotFoundException, SQLException{
Connection connection = getConnection();
String sql = "select count(1) from tb_car_desc where code = ? and lan_id = 15 ";
try {
PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1, make);
ResultSet rs = ps.executeQuery();
Long count = null;
while(rs.next()){
count = rs.getLong(1);
}


} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



}

}


/**
-- 插入数据成功 --
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at org.apache.commons.httpclient.ContentLengthInputStream.read(ContentLengthInputStream.java:169)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:107)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:126)
at org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMethodBase.java:684)
at test.GrabDTCByHttpClient.getBody(GrabDTCByHttpClient.java:86)
at test.GrabDTCByHttpClient.main(GrabDTCByHttpClient.java:247)
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(String.java:515)
at test.GrabDTCByHttpClient.main(GrabDTCByHttpClient.java:247)
**/
分享到:
评论

相关推荐

    [AB PLC例程源码][MMS_044666]Translation N-A.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    kolesar_3cd_01_0716.pdf

    kolesar_3cd_01_0716

    latchman_01_0108.pdf

    latchman_01_0108

    matlab程序代码项目案例:matlab程序代码项目案例MPC在美国高速公路场景中移动的车辆上的实现.zip

    matlab程序代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    pimpinella_3cd_01_0716.pdf

    pimpinella_3cd_01_0716

    petrilla_01_0308.pdf

    petrilla_01_0308

    [AB PLC例程源码][MMS_041452]Speed Controls in Plastic Extrusion.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    强化学习驱动下DeepSeek技术创新及其对AI发展的影响

    内容概要:本文档由张卓老师讲解,重点探讨DeepSeek的技术革新及强化学习对未来AI发展的重要性。文章回顾了AI的历史与发展阶段,详细解析Transformer架构在AI上半场所起到的作用,深入介绍了MoE混合专家以及MLA低秩注意机制等技术特点如何帮助DeepSeek在AI中场建立优势,并探讨了当前强化学习的挑战和边界。文档不仅提及AlphaGo和小游戏等成功案例来说明强化学习的强大力量,还提出了关于未来人工通用智能(AGI)的展望,特别是如何利用强化学习提升现有LLMs的能力和性能。 适用人群:本资料适宜对深度学习感兴趣的研究人员、开发者以及想要深入了解人工智能最新进展的专业人士。 使用场景及目标:通过了解最新的AI技术和前沿概念,在实际工作中能够运用更先进的工具和技术解决问题。同时为那些寻求职业转型或者学术深造的人提供了宝贵的参考。 其他说明:文中提到了许多具体的例子和技术细节,如DeepSeek的技术特色、RL的理论背景等等,有助于加深读者对于现代AI系统的理解和认识。

    有师傅小程序开源版v2.4.14+前端.zip

    有师傅小程序开源版v2.4.14 新增报价短信奉告 优化部分细节

    [AB PLC例程源码][MMS_047333]Motor Sequence Starter with timers to start.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    商城二级三级分销系统(小程序+后台含源码).zip

    商城二级三级分销系统(小程序+后台含源码).zip

    li_3ck_01b_0918.pdf

    li_3ck_01b_0918

    nicholl_3cd_01_0516.pdf

    nicholl_3cd_01_0516

    1995-2022年 网络媒体关注度、报刊媒体关注度与媒体监督相关数据.zip

    媒体关注度是一个衡量公众对某个事件、话题或个体关注程度的重要指标。它主要反映了新闻媒体、社交媒体、博客等对于某一事件、话题或个体的报道和讨论程度。 媒体监督的J-F系数(Janis-Fadner系数)是一种用于测量媒体关注度的指标,特别是用于评估媒体对企业、事件或话题的监督力度。J-F系数基于媒体报道的正面和负面内容来计算,从而为公众、研究者或企业提供一个量化工具,以了解媒体对其关注的方向和强度。 本数据含原始数据、参考文献、代码do文件、最终结果。参考文献中JF系数计算公式。 指标 代码、年份、标题出现该公司的新闻总数、内容出现该公司的新闻总数、正面新闻数全部、中性新闻数全部、负面新闻数全部、正面新闻数原创、中性新闻数原创、负面新闻数原创,媒体监督JF系数。

    [AB PLC例程源码][MMS_040315]Double INC and Double DEC of INT datatype.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    [AB PLC例程源码][MMS_047773]Convert Feet to Millimeters.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    [AB PLC例程源码][MMS_042349]How to read-write data to-from a PLC using OPC in Visual Basic 6.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    matlab程序代码项目案例:matlab程序代码项目案例论文代码 多篇RMPC 鲁棒模型预测控制Paper-code-implementation.zip

    matlab程序代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    lusted_3cd_02_0716.pdf

    lusted_3cd_02_0716

    pepeljugoski_01_0107.pdf

    pepeljugoski_01_0107

Global site tag (gtag.js) - Google Analytics