连接数据库问题?

dp1234 2003-09-29 01:38:08
为什么我用
Connection con=null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con=DriverManager.getConnection("jdbc:mysql://localhost/usdl");
String sql="select namefirst,namelast,email from students";
Statement stat=con.createStatement();
rs=stat.executeQuery(sql);
while(rs.next()){
String t1=rs.getString(1);
String t2=rs.getString(2);
String t3=rs.getString(3);
%>
<div align="center">
姓名:<%=t1%><%=t2%>;
E-mail:<%=t3%><br>
</div>
<%}%>
连接mysql数据库显示的都是乱码?


...全文
74 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
kathir 2003-10-26
  • 打赏
  • 举报
回复
同意楼上的
pxboy 2003-09-29
  • 打赏
  • 举报
回复
try:
姓名:<%=strToCn(t1)%><%=strToCn(t2)%>;

public String strToCn(String strIn)
{
byte[] byte1 = strIn.getBytes();
String temp = "";
try
{
temp = new String(byte1, "ISO8859_1");
}
catch (Exception e)
{
}
return temp;
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧