登录页面,库存管理页面
This commit is contained in:
41
src/main/java/com/example/Jdbc.java
Normal file
41
src/main/java/com/example/Jdbc.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.example;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class Jdbc {
|
||||
private Connection conn;
|
||||
private Statement stmt;
|
||||
private ResultSet rs;
|
||||
|
||||
Jdbc(){
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
String password = "root";
|
||||
String username = "root";
|
||||
conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/su?useSSL=false&serverTimezone=UTC", username, password);
|
||||
stmt=conn.createStatement();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet query(String sql) throws SQLException {
|
||||
rs=stmt.executeQuery(sql);
|
||||
return rs;
|
||||
}
|
||||
|
||||
public void update(String sql) throws SQLException {
|
||||
stmt.executeUpdate(sql);
|
||||
}
|
||||
public void close() throws SQLException {
|
||||
if(rs!=null){
|
||||
rs.close();
|
||||
}
|
||||
if(stmt!=null){
|
||||
stmt.close();
|
||||
}
|
||||
if(conn!=null){
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user