-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysqlConnection.java
More file actions
47 lines (25 loc) · 937 Bytes
/
mysqlConnection.java
File metadata and controls
47 lines (25 loc) · 937 Bytes
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
package mysqlConnection;
import java.sql.*;
//add mysql-connector-java-8.0.15 library to external libraries
public class mysqlConnection {
public static void main(String[] args) {
Connection con = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/mall?useUnicode=true&useLegacyDatetimeCode=false&serverTimezone=Turkey"
,"root","password");
Statement sqlState = con.createStatement();
String select = "select * from bim";
ResultSet rows = sqlState.executeQuery(select);
while(rows.next()) {
System.out.println(rows.getString("product"));
}
}
catch(SQLException ex) {
System.out.println("Ooops ! -> "+ ex.getMessage() +"error code -->" + ex.getErrorCode());
}
catch(ClassNotFoundException e) {
e.printStackTrace();
}
}
}