暑假生活每周总结5
本周完成了hadoop的hive数据库的配置,基本的使用数据存储使用语句使用sql语句进行了书写。
进一步熟悉hive数据库的操作。
import java.sql.*; import java.util.ArrayList; import java.util.List; public class Dao { public List<Load> selectAll(){ List<Load> list = new ArrayList<>(); try { Connection connection =HiveTool.getConnection(); Statement state = null; String sql="select * from test_load" ; PreparedStatement prepareStatement = connection.prepareStatement(sql); ResultSet rs = prepareStatement.executeQuery(); while(rs.next()) { String dt = rs.getString(1); String userid = rs.getString(2); String search = rs.getString(3); String url = rs.getString(4); Load load=new Load(dt,userid,search,url); list.add(load); } HiveTool.release(connection,prepareStatement,rs); }catch(SQLException e) { System.out.println("发生错误"); e.printStackTrace(); } return list; } }
基本的查询功能。
本周还学习了解码UTF-8
import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; public class JiaMi { public static void main(String[] args) throws UnsupportedEncodingException { String name="张三"; //url编码 String encode= URLEncoder.encode(name,"utf-8"); System.out.println(encode); //ISO-8859-1或者UTF-8 String dencode = URLDecoder.decode(encode,"utf-8"); System.out.println(dencode); /*对于get方法的数据转化*/ String de=URLDecoder.decode(encode,"ISO-8859-1"); byte[] bytes = de.getBytes("ISO-8859-1"); /* for (byte b :bytes){ System.out.print(b+" "); }*/ String s=new String(bytes,"UTF-8"); System.out.println(s); /*//*post解决方法*//* *//* request.setCharacterEncoding("UTF-8");*//* *//*get方法*//* String username = request.getParameter("username"); *//*byte[] bytes = username.getBytes("ISO-8859-1");//编码 String s=new String(bytes,"UTF-8");//解码*//* String s=new String(username.getBytes("ISO-8859-1"),"UTF-8"); System.out.println(s);*/ } }