1.我用的数据库是mysql。
import java.sql.*;
public class test1 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/program","root","123456");
Statement stmt=con.createStatement();
System.out.println("数据库连接成功");
String sql="select * from accontnum ";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
System.out.println("----"+rs.getString("password"));
}
}