手把手教你如何用JAVA连接MYSQL(mysql-connector-j-8.0.32.jar)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ConnMySql {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");
try (
Connection conn = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/xyytest",
"root",
"HUawei123");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select *"
+ " from employees"
+ " where department_id in ('10','20','30')")) {
while (rs.next()) {
System.out.println(rs.getInt(1) + " "
+ rs.getString(2) + " "
+ rs.getString(3) + " "
+ rs.getString(4) + " "
+ rs.getString(5));
}
}
}
}
您可能感兴趣的文章: