注册 登录
编程论坛 J2EE论坛

[求助]在Bean里连接数据库

地狱里的鸽子 发布于 2006-06-20 16:39, 911 次点击

html:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>

<body>
<form id="form1" name="form1" method="post" action="/loginWeb/houtai.jsp"> //action=/模块名/要提交的jsp名???
<table width="248" border="1">
<tr>
<td width="44">ming</td>
<td width="188"><label>
<input name="tname" type="text" id="tname" />
</label></td>
</tr>
<tr>
<td>ma</td>
<td><label>
<input name="tpwd" type="text" id="tpwd" />
</label></td>
</tr>
</table>
<p>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</p>
</form>
</body>
</html>


java Bean1:
import java.sql.*;
public class sqlBean {

public sqlBean() {
}
Connection con;

//得到con
public Connection getCon() throws ClassNotFoundException,
IllegalAccessException, InstantiationException
{
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").
newInstance();
con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;databasename=werkers","sa", "");
} catch (Exception ex) {
ex.printStackTrace();
}
return con;
}

}

java Bean2:
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.sql.*" %>
<jsp:useBean id="bean0" scope="session" class="sqlBean" />

<%
Connection conn;
Statement stm;
ResulSet rs;
String name=request.getParameter("tname");
String pwd =request.getParameter("tpwd");

conn=bean0.getCon();
stm=conn.createStatement();
stm.executeUpdate("insert into employee(name,password)values('"+name+"','"+pwd+"')");
stm.close();
conn.close();


%>
java Bean2 make出错:
"houtai.jsp": cannot find symbol; symbol : class sqlBean, location: class org.apache.jsp.houtai_jsp
"houtai.jsp": cannot find symbol; symbol : class sqlBean, location: class org.apache.jsp.houtai_jsp
"houtai.jsp": cannot find symbol; symbol : class sqlBean, location: class org.apache.jsp.houtai_jsp
"houtai.jsp": cannot find symbol; symbol : class ResulSet, location: class org.apache.jsp.houtai_jsp

我用JBuider 2005作的 请各位老大指点一下 谢了

7 回复
#2
千里冰封2006-06-20 18:36
sqlBean的class文件你放到哪里去了,有没有放到classes里面去?
#3
majunjie2006-06-21 09:26
这应该不是代码的错误,
也许你的路径错了.你检查你的路径是否正确啊
#4
地狱里的鸽子2006-06-22 14:52
sqlBean的class文件放到classes里面了 我是用JBuilder2005作的
路径问题 是那3个jar文件吗? 不知道在JBuilder2005里怎么陪
#5
szjstar2006-07-05 10:23
你的目的就是把输入的内容插入到数据库中。你使用的是JSP+JAVABEAN来操作数据库"houtai.jsp": cannot find symbol; symbol : class sqlBean, location: class org.apache.jsp.houtai_jsp 这句话。是不是houtai.jsp这个文件里是不是出错哦
#6
szjstar2006-07-05 10:25
前一段时间我是用SQLSEVER数据库连接着。配置都正确。就是连接不上,提示数据库用户名密码出错。郁闷了两天。原来是SQLSEVER必须打SP3以上的补丁。。
#7
千里冰封2006-07-05 12:24
也不一定,如果你是用JDBC:ODBC桥接的话,是不用打补丁的
只要设好数据源就可以了
并且驱动用SUN的默认驱动就可以了
sun.jdbc.odbc.JdbcOdbcDriver
#8
球球2006-07-11 13:55
如果是用JDBC:ODBC桥接SQLSERVER2000,写成:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:数据库名");

试试。

[此贴子已经被作者于2006-7-11 13:56:20编辑过]

1