JDBC路径问题
public class DeleteDocByThumbnailPath {
private static List getPathJDBC() throws
SQLException{
List l = new ArrayList();
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver"); //加载对应数据库的驱动
conn = (Connection) DriverManager.getConnection("jdbc:mysql://192.168.1.22:3306/rayzen?useUnicode=true&characterEncoding=UTF-8", "root", "zhaozy010203"); //根据对应数据库的url,user,password获取数据库连接
st = (Statement) conn.createStatement(); //创建用于执行静态 SQL 语句并返回它所生成结果的对象
rs = (ResultSet) st.executeQuery("select thumbnailPath from doc where projectid = '14j9wbLMfq_29'"); //用st执行sql,并保存在result中
while(rs.next()){
l.add(rs.getString("thumbnailPath"));
}
}catch(
ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}finally{
rs.close();
st.close();
conn.close();
}
return l;
}
private static void deleteFile(String path) {
File file = new File(path);
if (file.exists()) {
file.delete();
}
}
public static void main(String [] args) throws SQLException{
List list = getPathJDBC();
System.out.println("=================s====================");
for(int i = 0;i<list.size();i++){
String a = "C:/vfs/"+list;
System.out.println("==========a======="+a);
deleteFile(a);
}
System.out.println("================e==============");
}
}
小弟的代码,目的是删除thumbnailPath的所有图片,现在路径跟我对不上,他给我输出是这种:
C:/vfs[filedata/14j9wbLMfq_29/14j9wbLMfq_359634072664718281250_thumbnail.jpg
我想要的是:C:/vfs/filedata/14j9wbLMfq_29/14j9wbLMfq_359634072664718281250_thumbnail.jpg
------解决方案--------------------
你直接+list怎么可以。。
String a = "C:/vfs/"+(String)list.get(i);
------解决方案--------------------
System.out.println(file.delete()) ;
看看是否删除成功:true 成功 false 失败