引入外部jar包(mysql提供的Java使用者的連接器)
工程上右鍵>build path > config buildpath > liberies
>add external jars
>選擇對應的mysqlconnectorXXXXXXjar
看到工程上有jar文件則證明引入成功
編程
()注冊數據庫驅動
ClassforName(commysqljdbcDriver)
()創建連接
String url = jdbc:mysql://:/test;
String userName = root;
String password = root;
Connection conn = DriverManagergetConnection(url userName password)
()創建SQL信使
PreparedStatement stmt = conncreatePreparedStatement()
()執行SQL語句
int i = stmtexecuteUpdate(insert into employee values ( 張三豐 ))
()異常捕獲關閉資源
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25903.html