jdbc是可以對(duì)xampp中的數(shù)據(jù)庫(kù)進(jìn)行讀取。
1.需要使用最新的mysql-connection-java.jar包
2.這里面的mydb是xampp你需要讀取的數(shù)據(jù)庫(kù)名稱
3.test是你需要讀取數(shù)據(jù)庫(kù)中表的名稱
4.age是你需要讀取數(shù)據(jù)庫(kù)中表中對(duì)應(yīng)的age屬性
public static void main(String[] args ){
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mydb", "root", "");
Statement sta=con.createStatement();
ResultSet setOne=sta.executeQuery("select * from test");
while(setOne.next()){
System.out.println(setOne.getString("age"));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
經(jīng)過(guò)測(cè)試:

QQ截圖20160608080912.png