package javaexercise;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Q29jdbc {
static Connection newConnection = null;
public static Connection getDBConnection() throws SQLException {
try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/fidelity", "root", "root")) {
newConnection = con;
}
return newConnection;
}
public static void main(String[] args) throws SQLException {
getDBConnection();
Statement st = newConnection.createStatement();
String sql = "SELECT * FROM t_user";
ResultSet rs = st.executeQuery(sql);
//st.executeUpdate("INSERT INTO t_user VALUES(14,‘mabel‘,‘123456‘) ");
}
}
时间: 2024-12-14 19:57:15