-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.java
More file actions
36 lines (28 loc) · 1.44 KB
/
Data.java
File metadata and controls
36 lines (28 loc) · 1.44 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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
public class Data {
public void test() throws ClassNotFoundException ,SQLException{
String name ="root";
String pass = "";
String connUrl = "jdbc:mysql://localhost:3306/mysql";
Class.forName("com.mysql.jdbc.Driver");
try(Connection connection = DriverManager.getConnection(connUrl, name, pass)){
Statement statement = connection.createStatement();
statement.executeUpdate("drop table Books");
statement.executeUpdate("create TABLE IF NOT EXISTS Books(id MEDIUMINT NOT NULL AUTO_INCREMENT, name CHAR(30) NOT NULL, dt DATE, PRIMARY KEY(id));");
PreparedStatement preparedStatement = connection.prepareStatement("insert into Books (name, dt) values ('someNames',?)");
preparedStatement.setDate(1, new Date(1242444346));
preparedStatement.execute();
System.out.println(preparedStatement);
ResultSet resultSet = statement.executeQuery("select * from Books");
while (resultSet.next()){
System.out.println(resultSet.getDate("dt"));
}
CallableStatement callableStatement = connection.prepareCall("{call BookCount(?)}");
callableStatement.registerOutParameter(1, Types.INTEGER);
callableStatement.execute();
System.out.println(callableStatement.getInt(1));
}
}
}