import java.sql.*;
public class jdbc {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/temp";
String user = "root";
String password = "086123";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
String sql = "select * from people";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
System.out.print(rs.getString(2) + "\t");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
分享到:
评论