我的字符串标记生成器的错误处理
else if (sCarRental.equals("EP")) {
sStationCode = st.nextToken().trim();
sName=st.nextToken().trim();
sLocationCode = st.nextToken().trim();
sAddress1=st.nextToken().trim();
sAddress2=st.nextToken().trim();
sPostCode=st.nextToken().trim();
sCity=st.nextToken().trim();
sStationName=sName+sAddress1+sAddress2+sPostCode+sCity;
sStationType="C";
if(sLocationCode.equalsIgnoreCase("c"))
{
sStationArea="C";
}
else if (sLocationCode.equalsIgnoreCase("S"))
{
sStationArea="S";
}
else if (sLocationCode.equalsIgnoreCase("N"))
{
sStationArea="N";
}
else if (sLocationCode.equalsIgnoreCase("E"))
{
sStationArea="E";
}
else if (sLocationCode.equalsIgnoreCase("W"))
{
sStationArea="W";
}
else if (sLocationCode.equalsIgnoreCase("T"))
{
sStationArea="T";
}
else if (sLocationCode.equalsIgnoreCase("X"))
{
sStationArea="R";
}
else if (sLocationCode.equalsIgnoreCase("L"))
{
sStationArea="R";
}
else
{
sStationArea="C";
}
sSupplierCode ="EP";
sLocationCode=sStationCode.substring(0, 3);
sCrsCode = "EP";
}
我想读取一个 csv 文件并将其写入数据库
但是在这里我想添加一些错误处理..那么我该怎么做..通常我的 csv 文件应该包含 7 个值,如果只有 4 个值怎么办
? ..
else if (sCarRental.equals("EP")) {
sStationCode = st.nextToken().trim();
sName=st.nextToken().trim();
sLocationCode = st.nextToken().trim();
sAddress1=st.nextToken().trim();
sAddress2=st.nextToken().trim();
sPostCode=st.nextToken().trim();
sCity=st.nextToken().trim();
sStationName=sName+sAddress1+sAddress2+sPostCode+sCity;
sStationType="C";
if(sLocationCode.equalsIgnoreCase("c"))
{
sStationArea="C";
}
else if (sLocationCode.equalsIgnoreCase("S"))
{
sStationArea="S";
}
else if (sLocationCode.equalsIgnoreCase("N"))
{
sStationArea="N";
}
else if (sLocationCode.equalsIgnoreCase("E"))
{
sStationArea="E";
}
else if (sLocationCode.equalsIgnoreCase("W"))
{
sStationArea="W";
}
else if (sLocationCode.equalsIgnoreCase("T"))
{
sStationArea="T";
}
else if (sLocationCode.equalsIgnoreCase("X"))
{
sStationArea="R";
}
else if (sLocationCode.equalsIgnoreCase("L"))
{
sStationArea="R";
}
else
{
sStationArea="C";
}
sSupplierCode ="EP";
sLocationCode=sStationCode.substring(0, 3);
sCrsCode = "EP";
}
I want to read a csv file and write it to a database
But here i want to add some error handling .. So how can i do that ..normally my csv file should contain 7 values what if if there are only 4 values
help appreciated ..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能可以这样做...创建一个 API 以返回值(如果存在),否则抛出异常:-
在您的代码中,而不是调用
st.nextToken().trim()
,你调用该 API:-You probably could do something like this... create an API to return the value if exist, otherwise throw an exception:-
In your code, instead of calling
st.nextToken().trim()
, you call that API:-