'1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'
20 22 25 28 30 33 35 34 32 28 24 21
-8 8 10 15 18 -22 -24 -24 -21 -16 -50 -20
package bbb;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;public class T8 {public static void main(String[] args) throws Exception{//1.导入jar包//2.注册驱动//Class.forName("com.mysql.jdbc.Driver");Class.forName("com.mysql.cj.jdbc.Driver");//3.获取连接Connection con = DriverManager.getConnection("jdbc:mysql://mysql.sqlpub.com:3306/huangjin","laocooon","fc12f7a5215e8e0a");//4.获取执行者对象Statement stat = con.createStatement();//5.执行sql语句,并且接收结果String sql = "SELECT * FROM MonthlySorted";ResultSet rs = stat.executeQuery(sql);//6.处理结果String i1="",i2="",i3="";while(rs.next()) {i1+="'"+rs.getString(1)+"',";i2+=rs.getString(2)+" ";i3+=rs.getString(3)+" ";}i1=i1.substring(0,i1.length()-1);//去掉最后一个逗号System.out.println(i1);System.out.println(i2);System.out.println(i3);//7.释放资源con.close();stat.close();con.close();}
}