我正在尝试将spreadhseet.csv中的数据插入到我的数据库中,但无法解析布尔值。所有列的布尔值总是为false。
在我的传播中,我既有真,也有虚假,但当我上传到数据库时,它会使所有的错误保持不变。
我正在尝试解析具有布尔值为TRUE或FALSE
的in_service属性我需要两个值(真和假)
希望我做得对吗?
try {
// read line
String[] fileData;
String line = dis.readLine().replaceAll("\"", "");
fileData = line.split(",");
int tripID = Integer.parseInt(fileData[0]);
int driver_id = Integer.parseInt(fileData[1]);
String timestamp = fileData[2];
boolean in_service = Boolean.parseBoolean(fileData[3]);
int trips_pos = Integer.parseInt(fileData[4]);
double lat = Double.parseDouble(fileData[5]);
double lon = Double.parseDouble(fileData[6]);
int parish_id = Integer.parseInt(fileData[7]);
double distance = Double.parseDouble(fileData[8]);
int duration = Integer.parseInt(fileData[9]);
int trip_id = Integer.parseInt(fileData[10]);
double taxi_fare = Double.parseDouble(fileData[11]);
String query = " INSERT INTO aid_atidivyakumarpatra "
+ "(id, driver_id, date, in_service, trips_pos, lat, lon, point, parish_id, distance, duration, trip_id, taxi_fare)"
+ "VALUES ("+tripID+","+driver_id+",'"+timestamp+"',"+in_service+","+trips_pos+","
+ lat+","+lon+",ST_GeomFromText('POINT("+lon+" "+lat+")', 4326) , "+parish_id+","+distance+","+duration+", "
+ trip_id +","+taxi_fare +")";
答案 0 :(得分:0)
很抱歉我的回答,但真正的问题是为什么你不使用JPA(Java Persistence API)处理数据库? (实体经理,查询等......)
使用那种插入语句(连接),可能的SQL注入攻击非常高(我同意Reimeus)