时间:2021-07-01 10:21:17 帮助过:28人阅读
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‘) ");
}
}
JDBC connection
标签:.exe on() driver drive null static res user java