import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class Dbcon { //mysql8.0 url confing serverTimezone //配置jdbc的URL:jdbc:mysql://[IP]:[PORT]/[DB]?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true private static String URL = "jdbc:mysql://localhost:3306/dlt?serverTimezone=UTC"; private static String USER = "root"; private static String PASSWORD = "Ychina.9"; private static Connection con = null; public Dbcon(){} public static void main(String[] args) throws Exception { //mysql-connector-java-8.0.20 Class.forName("com.mysql.cj.jdbc.Driver"); con = DriverManager.getConnection(URL, USER,PASSWORD); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select q1,q2,q3,q4,q5,h1,h2 from detail where id = '7001'"); while(rs.next()){ System.out.println("Q1:" + rs.getString(1)); System.out.println("Q2:" + rs.getString(2)); System.out.println("Q3:" + rs.getString(3)); System.out.println("Q4:" + rs.getString(4)); System.out.println("Q5:" + rs.getString(5)); System.out.println("H1:" + rs.getString("h1")); System.out.println("H2:" + rs.getString("h2")); } } }标签:Java,getString,rs,System,mysql,println,链接,out From: https://www.cnblogs.com/kang2008/p/17187893.html