| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 770 人关注过本帖
标题:急求:JSP使用JAVABEAN连接ACCESS的问题
只看楼主 加入收藏
我爱动物
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-3-27
收藏
 问题点数:0 回复次数:3 
急求:JSP使用JAVABEAN连接ACCESS的问题

一个JSP文件处理登陆,里面用到了一个JAVABEAN,是用来处理数据库的,代码:
(JSP里的?不用管,是JSP里乱码问题)
JAVABEAN:
package opendb;
import java.sql.*;

public class opendb
{

String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:lfq_db";
Connection conn = null;
ResultSet rs = null;
public opendb()
{
try
{ Class.forName( sDBDriver );}
catch( java.lang.ClassNotFoundException e )
{ System.err.println( "opendb():"+ e.getMessage());}
}
public ResultSet executeQuery( String sql )
{
rs = null;
try
{
conn = DriverManager.getConnection( sConnStr,"damboo","123456");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery( sql );
}
catch( SQLException ex )
{System.err.println( "aq.executeQuery:" + ex.getMessage());}
return rs;
}

}

JSP:
<html>
<head>
<title>????</title>
<meta http-equiv = "Content-Type" content = "text/html; charset = "gb2312">
</head>
<style type = "text/css">
<!--@import "css/jsp.css";-->
</style>
<body bgcolor = "#ffffff">
<%@ page import = "java.sql.*"%>
<%@ page import = "java.util.*"%>
<jsp:useBean id = "jspEx" scope = "page" class = "opendb.opendb"/>
<%
boolean canLogon = true;
java.util.Date nowdate = new java.util.Date();
long logonTime = nowdate.getTime();
String nickName = request.getParameter( "nickName");
byte[] tmpbyte = nickName.getBytes("ISO8895_1");
nickName = new String( tmpbyte );
String passWord = request.getParameter( "passWord");
String sql = "select* form chatuser where nickName like '" + nickName +"'";
ResultSet rs = jspEx.executeQuery( sql );
if( rs.next())
{
String id = rs.getString( "id" );
String repwd = rs.getString( "passWord").trim();
long lastTime = rs.getLong( "logonTime" );
rs.close();
if(( logonTime-lastTime)>30*24*3600*1000)
{
sql = "updata chatuser set logonTime = '"+logonTime+"',passWord =' "+passWord+"' where nickName like '"+nickName+"'";
rs = jspEx.executeQuery( sql );
}
else{ if (repwd.compareTo(passWord)!=0)
{ canLogon = false; }
else
{
sql = "updata charuser set logonTime = '"+logonTime+"'wherenickName like'"+nickName+"'";
rs = jspEx.executeQuery(sql);
}
}
}
else
{
rs.close();
sql = "insert chatuser( nickName ,passWord,logonTime)values('"+nickName+"','"+passWord+"','"+logonTime+"')";
rs = jspEx.executeQuery( sql );
}
if ( !canLogon )
{%>
?????<br>
?????<a href = "javascript:history.back()">??</a>!
<%}
else
{
int num1 = 0;
int num2 = 0;
int num3 = 0;
sql = "select id from userlist where chatRoom like 'laugh'";
rs = jspEx.executeQuery(sql);
while( rs.next()) num1++;
rs.close();
sql = "select id from userlist where chatRoom like 'classmate'";
rs = jspEx.executeQuery(sql);
while(rs.next()) num2++;
rs.close();
sql = "select id form userlist where chatRoom like 'program'";
rs = jspEx.executeQuery(sql);
while(rs.next()) num3++;
rs.close();
%>
<div align = "center">
<table width = "400" border = "0" cellspacing = "0">
<tr bgcolor = "#ff5d26">
<td colspan = "2" height = "12">
<div align = "center"> <b><font color = "#ffffff">??</font><font color = "#ffffff">??
<%= nickName%>??JSP</font></b><div>
</td>
</tr>
<tr>
<td bgcolor = "#ffd6c8">?<br>
<br>
</td>
<td bgcolor = "#ffd6c8">??????
</td>
</tr>
<tr>
<td bgcolor = "#ffd6c8">?<br>
<br>
</td>
<td bgcolor = "#ffd6c8">?????
</td>
</tr>
<tr>
<td bgcolor = "#ffd6c8">?</td>
<td bgcolor = "#ffd6c8">??????</td>
</tr>
<tr>
<td bgcolor = "#ffd6c8">&nbsp</td>
<td bgcolor = "#ffd6c8">
<form name = "form1" method "post" action + "main.jsp">
<input type = "radio" name = "chatRoom" value = "laugh" checked>
????(<%=num1%>?)<br>
<input type = "radio" name = "chatRoom" value = "classmate" >
????(<%=num1%>?)<br>
<input type = "radio" name = "chatRoom" value = "program" >
????(<%=num1%>?)<br>
<input type = "submit" name = "Submit" value= "??">
<input type = "hidden" name = "nickName" value = "<%=nickName%>">
<br>
</form>
</td>
</tr>
</table>
</div>
<%}%>
</body>
</html>

出错:

java.io.UnsupportedEncodingException: ISO8895_1
	sun.io.Converters.getConverterClass(Unknown Source)
	sun.io.Converters.newConverter(Unknown Source)
	sun.io.CharToByteConverter.getConverter(Unknown Source)
	java.lang.StringCoding.encode(Unknown Source)
	java.lang.String.getBytes(Unknown Source)
	org.apache.jsp.Logon_jsp._jspService(Logon_jsp.java:70)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)




又是毕业设计上出的问题,哪位英雄救我!!!!


搜索更多相关主题的帖子: JSP ACCESS 
2006-05-20 12:01
yangwudong
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:244
专家分:0
注 册:2005-8-18
收藏
得分:0 
把byte[] tmpbyte = nickName.getBytes("ISO8895_1");
改成byte[] tmpbyte = nickName.getBytes("gb2312");

别做程序了,给你们一个赚钱的秘诀。做豆腐;if 做硬了 then 卖豆腐干;if 做稀了 then 卖豆腐花;if 太稀了 then 卖豆浆;if 豆腐卖不动了放几天 then 卖臭豆腐; else if 还卖不动放坏了 then 卖腐乳;
2006-05-20 16:43
yangwudong
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:244
专家分:0
注 册:2005-8-18
收藏
得分:0 

试试吧!我也不太清楚,信息太少了!


别做程序了,给你们一个赚钱的秘诀。做豆腐;if 做硬了 then 卖豆腐干;if 做稀了 then 卖豆腐花;if 太稀了 then 卖豆浆;if 豆腐卖不动了放几天 then 卖臭豆腐; else if 还卖不动放坏了 then 卖腐乳;
2006-05-20 16:44
我爱动物
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-3-27
收藏
得分:0 
恩,我来改下看
2006-05-21 15:10
快速回复:急求:JSP使用JAVABEAN连接ACCESS的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031174 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved