public class DBUtil { private static final String URL="jdbc:mysql://localhost:3306/test"; private static final String NAME="root"; private static final String PASSWORD="1234"; public static void main(String[] args) throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); Connection c=DriverManager.getConnection(URL,NAME,PASSWORD); Statement s=c.createStatement(); ResultSet rs=s.executeQuery("select user_name from goddess"); System.out.println(rs.getString("user_name")+","+rs.getInt("age")); System.out.println("adfasf"); } } 没有报错,也没有任何文字输出
ResultSet只能使用它里面的next()方法,逐个的读去数据
输出前加一句 rs.next(); 就可以了。