当前位置: 代码迷 >> Java Web开发 >> 怎么使用JAVA来解析此数据
  详细解决方案

怎么使用JAVA来解析此数据

热度:5719   发布时间:2013-02-25 21:11:25.0
如何使用JAVA来解析此数据
*HQ20015067394874,BA&A1300553047441412045763260019050912&E12345678&B0180000000#
我这里只有MFC来做的,如何转换成JAVA的呢?
CString strsave,strleft,strright,strright1,strreply,strtelnum,strcode,strhour,strminute,strsecond,strdate;
CString strlat,strlat1,strlng,strlng1,stryear,strmonth,strday,strspeed,strheading,strmileage;
GetDlgItem(IDC_EXTRACTDATA)->GetWindowText(strsave);

MessageBox(strsave);


//将接受到的数据进行处理,截取*与#之间的数据进行存储。
int num = 0;
int strsave_length = strsave.GetLength();
//strda = strda.Right(strda_length-6);
if(strsave_length >0)
{
int num = strsave.Find(_T(','));//查询*的unicode码

if(num > 0)
{
strleft = strsave.Left(num);//取逗号以前的数据。
MessageBox(strleft,"strleft = %s");
strreply = strleft.GetAt(5);//获取回复属性。
strtelnum = strleft.Right(11);//获取终端号码。
MessageBox(strreply,"strreply = %s");
MessageBox(strtelnum,"strtelnum = %s");

strright = strsave.Right(strsave_length-num-1);//取逗号以后的数据
MessageBox(strright,"strright = %s");

int strright_length = strright.GetLength();
strcode = strright.Left(2);//获取功能类型编码
strhour = strright.Mid(4,2);
strminute = strright.Mid(6,2);
strsecond = strright.Mid(8,2);

strlat = strright.Mid(10,2);
strlat1 = strright.Mid(12,6);
double lati = atof(strlat)+atof(strlat1)/(60*10000);//获取纬度数据
strlng = strright.Mid(18,3);
strlng1 = strright.Mid(21,7);
double lngi = atof(strlng)+atof(strlng1)/(60*10000);//获取经度数据

stryear = strright.Mid(strright_length-23-2,2);
strmonth = strright.Mid(strright_length-23-4,2);
strday = strright.Mid(strright_length-23-6,2);

strheading = strright.Mid(strright_length-23-8,2);
strspeed = strright.Mid(strright_length-23-10,2);

int heading = atoi(strheading);
int speed = atoi(strspeed);


int num1 = strright.Find(_T("&E"));
strright1 = strright.Right(strright_length-num1);//取&E及它以后的数据
strmileage = strright1.Mid(2,8);
int mileage = atoi(strmileage);

// MessageBox(strright1,"strright1 = %s");
// MessageBox(strmileage,"strmileage = %s");
// MessageBox(strlat1,"strlat1 = %s");
// MessageBox(strlng1,"strlng1 = %s");
// MessageBox(strhour,"strhour = %s");
// MessageBox(strminute,"strminute = %s");
// MessageBox(strsecond,"strsecond = %s");
// MessageBox(strright1,"strright1 = %s");
CString strsqlin,strlongitude,strlatitude,strtime;
strlongitude.Format("%f", lngi);
strlatitude.Format("%f", lati);
strtime.Format("20%s-%s-%s %s:%s:%s", stryear,strmonth,strday,strhour,strminute,strsecond);  
MessageBox(strtime,"time = %s");
// strsqlin.Format("INSERT INTO SmallCar(TelNumber) VALUES('%s')",strtelnum);
// strsqlin.Format("INSERT INTO SmallCar(TelNumber) VALUES ('"+strtelnum+"')");  
strsqlin.Format("INSERT INTO SmallCar(TelNumber,PositioningTime,Longitude,Latitude, Speed,Heading,Mileage,Reply,FunctionTypeCode) VALUES('"+strtelnum+"','"+strtime+"','"+strlongitude+"','"+strlatitude+"','"+strspeed+"','"+strheading+"','"+strmileage+"','"+strreply+"','"+strcode+"')");  


try{

m_pRecordset1= m_pConnection1->Execute(_bstr_t(strsqlin), NULL, adCmdText); // 获得记录集
}
catch (_com_error d)
{
AfxMessageBox("执行SQL失败!");
return;
}  
}
else
{
MessageBox("解析数据失败,请确定收到的数据格式!!");
}
}
else
{
MessageBox("没有数据可供分解存入数据库!!");
  相关解决方案