Commit 56930a03 by Patryk Czarnik

uzupełnienia JDBC

parent d80d6a45
......@@ -6,3 +6,4 @@
/*.iml
/.idea/
/hr.db
......@@ -18,5 +18,10 @@
<artifactId>postgresql</artifactId>
<version>42.7.5</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.49.1.0</version>
</dependency>
</dependencies>
</project>
......@@ -14,7 +14,8 @@ import java.sql.Statement;
public class Oracle {
public static void main(String[] args) {
final String url = "jdbc:oracle:thin:@//10.0.15.13:1521/xe";
// final String url = "jdbc:oracle:thin:@//10.0.15.13:1521/xe";
final String url = "jdbc:oracle:thin:@//10.0.15.13:1521/xepdb1";
try(Connection con = DriverManager.getConnection(url, "HR", "abc123")) {
try(Statement st = con.createStatement()) {
final String sql = "SELECT * FROM countries";
......
......@@ -36,7 +36,7 @@ public class P07_GenerowaneId {
int ile = stmt.executeUpdate();
System.out.println("Wstawiono " + ile + " rekord"); // powinno być 1
// odcyt wartości wygenerowanych pól
// odczyt wartości wygenerowanych pól
try(ResultSet rsGen = stmt.getGeneratedKeys()) {
if(rsGen.next()) {
int id = rsGen.getInt(1);
......
......@@ -68,6 +68,11 @@ public class P09_DowolnaKolejnoscResultSet {
System.out.printf("\npoz %3d - nie ma takiej pozycji\n", poz);
}
}
if(rs.last()) {
System.out.println("\nJestem w ostatnim rekordzie");
int nr = rs.getRow();
System.out.println("Numer pozycji " + nr + ", nazwisko pracownika: " + rs.getString("last_name"));
}
}
}
} catch (SQLException e) {
......
......@@ -19,6 +19,7 @@ public class P11_Metadane {
System.out.println(dbMetaData.getDatabaseProductName());
System.out.println(dbMetaData.getDatabaseMajorVersion()
+ "." + dbMetaData.getDatabaseMinorVersion());
System.out.printf("maxStatements: " + dbMetaData.getMaxStatements());
System.out.println();
try(ResultSet tables = dbMetaData.getTables(null, "public", null, null)) {
......
......@@ -16,7 +16,7 @@ public class P14c_Procedura_OdczytWartosciSkalarnej {
int nr = sc.nextInt();
try(Connection c = DriverManager.getConnection(Ustawienia.URL, Ustawienia.USER, Ustawienia.PASSWD);
CallableStatement stmt = c.prepareCall("{?= call nazwisko_szefa(?)}")) {
CallableStatement stmt = c.prepareCall("{? = call nazwisko_szefa(?)}")) {
stmt.setInt(2, nr);
stmt.registerOutParameter(1, Types.VARCHAR);
System.out.println(stmt);
......
url=jdbc:postgresql://localhost/hr
user=alx
password=abc123
tcpKeepAlive=true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment