把数据库表中的数据一行一行的写入文本文件,并且每个字段加上分隔符

Java code FileWriter fw = new FileWriter("myfile.txt"); Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/microblog","root","admin"); Statement st=con.createStatement(); ResultSet rs= st.executeQuery("select * from t_users"); //可以用这个取列名,或者在这里输出你第一行的表头 ResultSetMetaData rsmd = rs.getMetaData(); int col = rsmd.getColumnCount(); while (rs.next()) { for (int i = 1; i

你可能感兴趣的:(io流)