Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String args[]) {
- Connection conn = null;
- PreparedStatement prsment = null;
- ResultSet res = null;
- try {
- String usname = "devdbuser";
- String usPassword = "postgres";
- String host = "jdbc:postgresql://localhost:5432/devdb";
- String drayver = "org.postgresql.Driver";
- Class.forName(drayver);
- conn = DriverManager.getConnection(host, usname, usPassword);
- prsment = conn.prepareStatement("SELECT FROM Users");
- res = prsment.executeQuery();
- while (res.next()){
- System.out.print(res.getString(2) + " ");
- System.out.print(res.getString(3) + " ");
- System.out.print(res.getString(4) + " ");
- System.out.print(res.getString(5) + " ");
- System.out.print(res.getString(6) + " ");
- System.out.print(res.getInt(7));
- }
- /* while (res.next()){
- int userID = res.getInt("userId");
- String userN = res.getString("userName");
- String userF = res.getString("userFam");
- String userLog = res.getString("userLogin");
- String userPsw = res.getString("userPass");
- String userPos = res.getString("userEmail");
- String userEm = res.getString("userEmail");
- int userVozrast = res.getInt("userAge");
- System.out.println(userID + " " + userN + " "+ userF + " " + userLog + " " + userPsw + " " + userPos + " " + userEm + " " + userVozrast);
- }*/
- } catch (Exception n) {
- System.out.println("Другая ошибка, проверьте свой код");
- }
- catch (ClassNotFoundException e) {
- System.out.println("Проверьте драйвера, правильно ли указали ");
- } catch (SQLException e) {
- System.out.println("Не удалось подключение к БД");
- }
- finally{ try{
- if (res!=null){
- res.close();
- }
- if (prsment!=null){
- prsment.close();
- }
- if (conn!=null){
- conn.close();
- }
- } catch (SQLException e) {
- System.out.println("Razyedinenie ne udalos, ili Oshibka pri SQL zaprosa");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement