Chinaorg

          于千萬(wàn)人之中,遇見(jiàn)你所遇見(jiàn)的人;于千萬(wàn)年之中,時(shí)間的無(wú)涯荒野里,沒(méi)有早一步,也沒(méi)有晚一步,剛巧趕上了
          我不去想是否能夠成功,既然選擇了遠(yuǎn)方,便只顧風(fēng)雨兼程; 我不去想,身后會(huì)不會(huì)襲來(lái)寒風(fēng)冷雨,既然目標(biāo)是地平線,留給世界的只能是背影
          posts - 20, comments - 6, trackbacks - 0, articles - 0

          Mysql5.0中文亂碼解決方案

          Posted on 2006-10-08 21:43 chinaorg 閱讀(381) 評(píng)論(0)  編輯  收藏 所屬分類: MYSQL
          最近學(xué)到j(luò)sp連接數(shù)據(jù)庫(kù)那一塊的時(shí)候,我也遇到了中文亂碼問(wèn)題~~呵呵,很頭疼哦!
          ???我用的數(shù)據(jù)庫(kù)是Mysql5.0,所以,我先用google,baidu等上網(wǎng)搜了一下解決方案,自己也按著方法反復(fù)測(cè)試了一、兩天之后,終于解決了我的JSP+Mysql5.0+tomcat-5.0.29出現(xiàn)的亂碼問(wèn)題。
          ???解決方案如下:
          ???1、在dos環(huán)境下,用mysql?--default-character-set=gbk?-u?root?-p?這句話進(jìn)入mysql~~
          ?????2、建數(shù)據(jù)庫(kù)、表,如下:
          ???????
          create?database?admin;
          ???????????use?admin;

          ???????????CREATE?TABLE?admin?(
          ???????????admin_name?char(20)?NOT?NULL,
          ???????????admin_password?char(20)?NOT?NULL
          ???????????)?TYPE=MyISAM,
          ???????????default?character?set?gbk;


          ?????3、接著用如下testgbk.jsp測(cè)試,
          <%@?page?contentType="text/html;?charset=gbk"?language="java"?import="java.sql.*"?import="java.io.*"?%>
          <%?
          Connection?conn?=?null;
          Class.forName("com.mysql.jdbc.Driver");?
          conn?=DriverManager.getConnection("jdbc:mysql://localhost:3306/admin?user=root&password=123456&useUnicode=true&characterEncoding=gbk");
          Statement?stmt=conn.createStatement();
          ResultSet?rs=null;
          %>
          <html>
          <head>
          <meta?http-equiv="Content-Type"?content="text/html;?charset=gbk">
          <title></title>
          </head>
          <body>
          <table?width="314"?height="34"?border="0"?align="center"?cellpadding="0"?cellspacing="0"?bgcolor="#6666FF">
          ??<tr>?
          ????<td?align="center"?height="19"?width="100"?style="font-size:10pt;color:red;">帳號(hào)</td>
          ????<td?align="center"?height="19"?width="40"?style="font-size:10pt;color:red;">密碼</td>
          ??</tr>?
          <%?
          String?temp?=?"insert?into?admin(admin_name,admin_password)?values('你們好','123')";
          PreparedStatement?pst?=?conn.prepareStatement(temp);
          pst.executeUpdate();
          pst.close();
          //結(jié)束
          temp?=?"select?*?from?admin";
          rs=stmt.executeQuery(temp);
          while(rs.next()){
          String?admin=rs.getString("admin_name");
          String?pass=rs.getString("admin_password");
          %>
          ??<tr>?
          ????<td?align="center"?height="19"?width="100"?style="font-size:10pt;color:blue;"><%=admin%></td>
          ????<td?align="center"?height="19"?width="40"?style="font-size:10pt;color:blue;"><%=pass%></td>
          </tr>?
          <%
          }
          %>
          <%??
          rs.close();
          stmt.close();
          conn.close();?
          %>
          ??<tr>?
          ????<td?height="19"?colspan="4"?align="center"?style="font-size:10pt;color:red;">?</td>
          ??</tr>
          </table>
          </body>
          </html>


          好了,現(xiàn)在讓你頭疼的mysql中文亂碼問(wèn)題是不是已經(jīng)迎刃而解了呢?~~呵呵,搞定

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 汝阳县| 长汀县| 宁武县| 关岭| 外汇| 崇文区| 东城区| 伊吾县| 石屏县| 民和| 孟连| 德钦县| 那坡县| 漳平市| 准格尔旗| 壶关县| 石柱| 延吉市| 类乌齐县| 信丰县| 徐闻县| 界首市| 大悟县| 咸阳市| 和政县| 通州区| 彰武县| 自治县| 昌宁县| 伊春市| 武义县| 林甸县| 新巴尔虎左旗| 昭苏县| 白河县| 乐昌市| 丹江口市| 无锡市| 阿荣旗| 晋州市| 四会市|