查看完整版本: 各位帮我看小这个问题出现在哪里嘛~~谢谢了

ligang242510 2007-12-26 10:39

各位帮我看小这个问题出现在哪里嘛~~谢谢了

我用的是JSP+JAVABEAN+SQL实现插入的功能`页面可以运行就是~连不到数据~请各位帮我看下嘛~
这个JAVABEAN 是SET和GET的方法~
package com.liuyan;
public class message {
** String title;
** String name;
** String email;
** String content;
public void setTitle(String title){this.title=title;}
public void setName(String name){this.name=name;}
public void setEmail(String email){this.email=email;}
public void setContent(String content){this.content=content;}
public String getTitle(){return this.title;}
public String getName(){return this.name;}
public String getEmail(){return this.email;}
public String getContent(){return this.content;}

}

这个是实现数据库连接和插入功能的JAVABEAN
package com.liuyan;
import java.sql.*;
import java.util.*;
public class messageBean {
** Connection con;
message msg;
public messageBean(){
        try{
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con=DriverManager.getConnection("jdbc:odbc:sun","sa","");
        }
        catch(Exception e)
        {
                e.printStackTrace();
                }
}
public void setMessage(message msg){
        this.msg=msg;
}
public void addMessage()throws Exception{
        try{
               
                PreparedStatement stm=con.prepareStatement("insert into liuyan values(?,?,?,?,)");
                stm.setString(1, msg.getTitle());
                stm.setString(2, msg.getName());
                stm.setString(3, msg.getEmail());
            stm.setString(4, msg.getContent());
        }
  catch(Exception e){
          e.printStackTrace();
          throw e;
  }
}
}

这个是JSP的首页
<%@page contentType="text/html;charset=gb2312"%>
<!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>
<style type="text/css">
<!--
.STYLE1 {font-size: 18px}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="addMessage.jsp">
  <table width="353" height="298" border="0" align="center">
    <tr>
      <td height="38" colspan="5" bgcolor=""><div align="center" class="STYLE1">访客留言</div></td>
    </tr>
    <tr>
      <td width="3" height="296" rowspan="5">&nbsp;</td>
      <td width="73" height="25" bgcolor="#339966"><div align="right">姓名:</div></td>
      <td colspan="2" bgcolor="#339966"><label>
        <input type="text" name="name"  width="150" height="20"/>
      </label></td>
      <td width="71" rowspan="5" bgcolor="#339966">&nbsp;</td>
    </tr>
    <tr>
      <td height="25" bgcolor="#339966"><div align="right">E-mail:</div></td>
      <td height="25" colspan="2" bgcolor="#339966"><label>
        <input type="text" name="email" width="150" height="20" />
      </label></td>
    </tr>
    <tr>
      <td height="25" bgcolor="#339966"><div align="right">主题:</div></td>
      <td height="25" colspan="2" bgcolor="#339966"><label>
        <input type="text" name="title"  width="150"  height="20"/>
      </label></td>
    </tr>
    <tr>
      <td height="135" bgcolor="#339966"><div align="right"><span class="STYLE1">留言:</span></div></td>
      <td height="135" colspan="2" bgcolor="#339966"><label>
        <textarea name="content" rows="10" with="20"></textarea>
      </label></td>
    </tr>
    <tr>
      <td height="23" bgcolor="#339966"><label>
        <input type="submit" name="Submit" value="提交" />
      </label></td>
      <td width="96" height="23" bgcolor="#339966">&nbsp;</td>
      <td width="88" bgcolor="#339966"><label>
        <input type="reset" name="Submit2" value="重置" />
      </label></td>
    </tr>
  </table>
</form>
</body>
</html>

最后一个是处理数据的JSP
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="com.liuyan.*,java.util.*,java.sql.* "%>
<%@page language="java" %>
<html>
  <body>
   <jsp:useBean id="message" class="com.liuyan.message" scope="page">
  <jsp:setProperty name="message" property="*"/>
  </jsp:useBean>
  <jsp:useBean id="messageBean" class="com.liuyan.messageBean" scope="page"/>
   
  <%
  
   messageBean.setMessage(message);
  messageBean.addMessage();
   %>

  </body>
</html>
页: [1]

查看完整版本: 各位帮我看小这个问题出现在哪里嘛~~谢谢了