33 lines
893 B
Java
33 lines
893 B
Java
package com.benchmark.util;
|
|
|
|
import com.benchmark.model.User;
|
|
|
|
import java.sql.*;
|
|
|
|
public class DbUtil {
|
|
|
|
public static void createSchema(Connection conn) throws SQLException {
|
|
try (Statement stmt = conn.createStatement()) {
|
|
stmt.execute("""
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id INTEGER PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
email TEXT NOT NULL,
|
|
age INTEGER NOT NULL,
|
|
created_at INTEGER NOT NULL
|
|
)
|
|
""");
|
|
}
|
|
}
|
|
|
|
public static User mapRow(ResultSet rs) throws SQLException {
|
|
return new User(
|
|
rs.getLong("id"),
|
|
rs.getString("name"),
|
|
rs.getString("email"),
|
|
rs.getInt("age"),
|
|
rs.getLong("created_at")
|
|
);
|
|
}
|
|
}
|