import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
//在項目中, 新建了一個lib文件,用來放jar包
public class DBHelper {
public static void main(String[] args) throws Exception {
String url = "jdbc:mysql://localhost:3307/fuqiming"; // ?端口號 ?我的是 3307. 默認的是3306.
String sql = "insert into test(name,job) values('影魔','中單')";
String name = "com.mysql.jdbc.Driver";
String user = "fqm";
String password = "fqm";
Class.forName(name); // 指定連接類型
Connection conn = DriverManager.getConnection(url, user, password);// 獲取連接
PreparedStatement pst = conn.prepareStatement(sql);// 準備執行語句
pst.executeUpdate();// 執行 UPDATE;
System.out.println("執行" + sql + "語句成功");}}
=====================================