另附上一篇jdbc查询代码,有空再来整理
我用的mysql
需要导入jar包:mysql-jar\mysql-connector-java-5.1.47-bin.jar
2019-05-14 02:43:22
package slect;import java.sql.*;public class Select {public static void main(String[] args){ String url = "jdbc:mysql://localhost:3306/大吉大利"; String user = "root"; String password = "123456"; try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection(url, user, password); if(!conn.isClosed()) System.out.println("登陆成功"); Statement statement = conn.createStatement(); String sql = "select * from persion"; ResultSet rs = statement.executeQuery(sql); while(rs.next()) { String id=rs.getString(1); String name=rs.getString(2); System.out.println(id+name); } rs.close(); conn.close(); } catch(Exception e) { e.printStackTrace(); }} }