常识一:让Mysql支持中文 打开my.ini文件, 找到default-character-set,一共有两处,全部改成default-character-set=gbk
重启Mysql,就行了!
常识二:Mysql的建库、建表、插入
- 建库:
- mysql>>createdatabaseamou;
- 改用别的库:
- mysql>>useamou;
- 在amou数据库里建表:
- mysql>>CREATETABLEtool(
- IDBIGINTNULLAUTO_INCREMENTPRIMARYKEY,
- NameVARCHAR(255)NULL,
- urlVARCHAR(255)NULL,
- NoteTEXTNULL,
- SizeVARCHAR(255)NULL,
- LevelINTNULL,
- TypeVARCHAR(255)NULL
- )TYPE=innodb;
- 插入数据:
- mysql>>insertintotool(Name)values("amouname");
- mysql>>select*fromtool;
- 插入数据:
- mysql>>insertintotoolvalues(0,"amoutest","http://www.baidu.com","test","2.8MB",5,"rar");
- mysql>>select*fromtool;
常识三:JDBC实现增删查改(指定参数)
- importjava.sql.*;
- publicclassOperateUser{
- Stringdriver="com.mysql.jdbc.Driver";
- Stringurl="jdbc:mysql://localhost:3306/test";
- Stringname="root";
- Stringpassword="123456";
- staticConnectionconn=null;
- Statementst=null;
- ResultSetrs=null;
- Stringsql=null;
- publicvoidadd(){
- try{
- sql="insertintotuservalues(60024054,'某某','男',24,'广东省广州市')";
- Class.forName(driver);
- conn=DriverManager.getConnection(url,name,password);
- st=conn.createStatement();
- st.executeUpdate(sql);
- conn.close();
- }catch(Exceptione){
- e.printStackTrace();
- }
- }
- publicvoiddelete(){
- try{
- sql="deletefromtuserwhereid=60024054";
- Class.forName(driver);
- conn=DriverManager.getConnection(url,name,password);
- st=conn.createStatement();
- st.executeUpdate(sql);
- st.close();
- conn.close();
- }catch(Exceptione){
- e.printStackTrace();
- }
- }
- publicvoidfind(){
- try{
- sql="select*fromtuser";
- Class.forName(driver);
- conn=DriverManager.getConnection(url,name,password);
- st=conn.createStatement();
- rs=st.executeQuery(sql);
- while(rs.next()){
- System.out.println(rs.getInt(1)+"/t"+rs.getString(2)+"/t"
- +rs.getString(3)+"/t"+rs.getInt(4)+"/t"
- +rs.getString(5));
- }
- rs.close();
- st.close();
- conn.close();
- }catch(Exceptione){
- e.printStackTrace();
- }
- }
- publicvoidupdate(){
- try{
- sql="updatetusersetid=60024410,name='某某',sex='女',age=24,addr='广东深圳'";
- Class.forName(driver);
- conn=DriverManager.getConnection(url,name,password);
- st=conn.createStatement();
- st.executeUpdate(sql);
- st.close();
- conn.close();
- }catch(Exceptione){
- e.printStackTrace();
- }
- }
- }
- //出处:http://blog.csdn.net/quanleilei123/archive/2009/12/15/5014194.aspx