嘗試{
class . forname(" org . gjt . mm . MySQL . driver ");
string URL = " JDBC:MySQL://"+IP+":"+port+"/"+sid+"?user = "+name+" & amp;password = "+pass+" & amp;useUnicode = true & ampcharacter encoding = utf-8 ";
//myDB是數據庫名稱。
connection conn = driver manager . get connection(URL);
}catch(異常e){
System.out.println("數據庫連接出錯-MySQL "+e . getmessage());
}
2.創建preparestatement對象。
String sql = "插入到userinfo (id)值(?)";
prepared statement pstam = con . prepare statement(SQL);
pstam.setInt(1,u . getid());
pstam . execute update();//執行插入。
3.關閉連接
con . close();
————————————————————
修改表格結構
alter table test add test varchar(50);