-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
83 lines (60 loc) · 2.08 KB
/
Copy pathmain.java
File metadata and controls
83 lines (60 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.company;
/**
*
* @author pkopicki
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Connection conn = null;
try
{
String userName = "root";
String password = "Biggk123";
String sterownik;
sterownik = "com.mysql.cj.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/dziennik?autoReconnect=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&verifyServerCertificate=false";
Class.forName (sterownik);
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
Statement st = conn.createStatement();
ResultSet rs;
rs = st.executeQuery("SELECT * FROM users");
while (rs.next())
{
String imie = rs.getString("Imie");
String nazwisko = rs.getString("Nazwisko");
String user_name = rs.getString("user_name");
String pass = rs.getString("password");
String plec = rs.getString("plec");
String data_ur = rs.getString("data_ur");
System.out.println(imie + "\t" + nazwisko + "\t" + user_name + "\t" + pass + "\t" + plec + "\t" + data_ur);
}
}
catch (ClassNotFoundException | SQLException e)
{
System.out.println( e.getCause());
System.err.println ("Cannot connect to database server");
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (SQLException e) { /* ignore close errors */ }
}
}
}
}