jsp连接mysql乱码问题
jsp吧
全部回复
仅看楼主
level 1
一滩死水 楼主
为什么用jsp连接mysql的时候,向表中插入中文数据时.表中得到的是乱码.而读取mysql数据库里表的内容使用<%request.setCharacterEncoding("gb2312");%>读取得到的是乱码.而使用new String(rs.getString(1).getBytes("ISO8859-1"));就可以得到中文..怎么解决呢?我晕啊...乱码好烦人啊...求前辈们帮帮忙啊:代码如:<%@ page contentType="text/html;charset=gb2312"%><%@ page import="java.sql.*"%><%request.setCharacterEncoding("gb2312");%><% String DRIVER="com.mysql.jdbc.Driver"; String DBURL="jdbc:mysql://localhost/bdifn?user=root&password=1234"; Connection conn =null; Statement stmt=null; try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException e) { out.println("class not found!!");}try{ conn=DriverManager.getConnection(DBURL); stmt=conn.createStatement(); stmt.executeUpdate("insert into note values(null,'你好啊','好啊','乱七八糟的啊~')");}catch(Exception e){ e.printStackTrace();}finally{try{ if(stmt!=null){ stmt.close(); stmt=null; } if(conn!=null){ conn.close(); conn=null; } }catch(Exception e) { e.printStackTrace(); }}%>
2007年03月29日 12点03分 1
level 1
你可以在前面加上:<% request.setCharacterEncoding("gbk"); %>强制用GBK,默认的是ISO-8859
2007年04月10日 17点04分 2
1