Mageia Bugzilla – Attachment 14497 Details for
Bug 33051
postgresql-jdbc new security issue CVE-2024-1597
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
really basic java connect to postgres (Java 17)
postMan.java (text/x-csrc), 1.14 KB, created by
Brian Rockwell
on 2024-04-11 04:56:24 CEST
(
hide
)
Description:
really basic java connect to postgres (Java 17)
Filename:
MIME Type:
Creator:
Brian Rockwell
Created:
2024-04-11 04:56:24 CEST
Size:
1.14 KB
patch
obsolete
>//package postgresql.jdbc; >import java.sql.Connection; >import java.sql.DriverManager; >import java.sql.SQLException; >import java.sql.Statement; >import java.sql.ResultSet; >public class postMan { > public static void select_row(Connection con) throws SQLException { > String query = "select brand, model,year from cars"; > try (Statement stmt = con.createStatement()) { > ResultSet rs = stmt.executeQuery(query); > while (rs.next()) { > String brand = rs.getString("brand"); > String model = rs.getString("model"); > int year = rs.getInt("year"); > System.out.println(brand + ", " + model + ", " + year); > } > } catch (SQLException e) { > System.out.println(e); > } > } > public static void main(String[] args) { > // establishes database connection > String url = "jdbc:postgresql://localhost/m"; > try (Connection connection = DriverManager.getConnection(url, "mageia", "mageia5")) { > System.out.println("Connection established successfully"); > select_row(connection); > } catch (SQLException e) { > System.out.print(e.getMessage()); > } > } >}
//package postgresql.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.sql.ResultSet; public class postMan { public static void select_row(Connection con) throws SQLException { String query = "select brand, model,year from cars"; try (Statement stmt = con.createStatement()) { ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String brand = rs.getString("brand"); String model = rs.getString("model"); int year = rs.getInt("year"); System.out.println(brand + ", " + model + ", " + year); } } catch (SQLException e) { System.out.println(e); } } public static void main(String[] args) { // establishes database connection String url = "jdbc:postgresql://localhost/m"; try (Connection connection = DriverManager.getConnection(url, "mageia", "mageia5")) { System.out.println("Connection established successfully"); select_row(connection); } catch (SQLException e) { System.out.print(e.getMessage()); } } }
View Attachment As Raw
Actions:
View
Attachments on
bug 33051
: 14497