import java.sql.* ; public class App { public static void main(String[] args) throws Exception { System.out.println("Hello, World!"); Class.forName("com.mysql.cj.jdbc.Driver"); Connection conn = null; Statement stmt = null; String url="jdbc:mysql://數(shù)據(jù)庫IP/數(shù)據(jù)庫名?useUnicode=true&characterEncoding=UTF-8&userSSL=false&serverTimezone=GMT%2B8"; String user="root"; String password="123456"; conn = DriverManager.getConnection(url,user,password); stmt = conn.createStatement(); // String SQL = "INSERT INTO test1 VALUES(10001,老李,男,35)";//增 // String SQL = "delete from test1 where id=10001";//刪 // String SQL = "update test1 set (id=10010,老六,女,66) where id=10001";//改 // stmt.executeUpdate(SQL); String SQL = "select * from test1";//查 ResultSet rs = stmt.executeQuery(SQL); while(rs.next()){ int id = rs.getInt("id");//錄入 String name = rs.getString("name"); String sex = rs.getString("sex"); int age = rs.getInt("age"); System.out.print("id: " + id+" ");//顯示 System.out.print("name: " + name+" "); System.out.print("sex: " + sex+" "); System.out.println("age: " + age+" "); } rs.close(); stmt.close(); conn.close(); } }
?
本文摘自 :https://www.cnblogs.com/