jsp 在问文本读取后 插入数据库。但是老是报错,下面是代码。请帮忙看看问题出在哪 50
<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%><%@pageimport="java.s...
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.sql.*" %>
<%@ page import="java.io.*,java.sql.*,java.text.*,java.util.Date,java.util.*,java.math.*,java.net.*,java.lang.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JSP读取数据库</title>
</head>
<body>
<jsp:useBean id="DB" class="Javabean.DBbean"></jsp:useBean>
<%
request.setCharacterEncoding("gb2312");
Connection conn=DB.getConn();
//Statement statement=conn.createStatement();
String fSrcName="D/FileUpload/123.txt";
BufferedReader br = new BufferedReader(new FileReader(fSrcName)) ; //读文件
List list = new ArrayList(); //放置读取的内容
String[] str ;
String s;
while( (s = br.readLine()) != null)
{
str = s.split("\\s+");
list.add(str);
}
//插入数据库
String sql="insert into user(ID,PWD,authority)values(?,?,?)";
PreparedStatement pstmt =DB.prepar(conn, sql);
DB.executeUpdate(pstmt, sql);
for(int i=0; i<list.size(); i++)
{
String[] temp = (String[])list.get(i) ;
pstmt.setString(1, temp[0]);
pstmt.setString(2, temp[1]);
pstmt.setString(3, temp[2]);
DB.executeUpdate(pstmt, sql);
}
%>
<%
pstmt.close();
conn.close();
%>
</body>
</html> 展开
<%@page import="java.sql.*" %>
<%@ page import="java.io.*,java.sql.*,java.text.*,java.util.Date,java.util.*,java.math.*,java.net.*,java.lang.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JSP读取数据库</title>
</head>
<body>
<jsp:useBean id="DB" class="Javabean.DBbean"></jsp:useBean>
<%
request.setCharacterEncoding("gb2312");
Connection conn=DB.getConn();
//Statement statement=conn.createStatement();
String fSrcName="D/FileUpload/123.txt";
BufferedReader br = new BufferedReader(new FileReader(fSrcName)) ; //读文件
List list = new ArrayList(); //放置读取的内容
String[] str ;
String s;
while( (s = br.readLine()) != null)
{
str = s.split("\\s+");
list.add(str);
}
//插入数据库
String sql="insert into user(ID,PWD,authority)values(?,?,?)";
PreparedStatement pstmt =DB.prepar(conn, sql);
DB.executeUpdate(pstmt, sql);
for(int i=0; i<list.size(); i++)
{
String[] temp = (String[])list.get(i) ;
pstmt.setString(1, temp[0]);
pstmt.setString(2, temp[1]);
pstmt.setString(3, temp[2]);
DB.executeUpdate(pstmt, sql);
}
%>
<%
pstmt.close();
conn.close();
%>
</body>
</html> 展开
5个回答
展开全部
将eclipse编码格式全部换成UTF-8试试看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
jsp标签 sa.jsp 第18行 有标签 编写错误 你好好看一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询