使用JavaBean不能插入MySQL数据库

tomsy2000 2015-01-23 04:04:40
这是JSP页面,参数都能正确传过来,就是不能插入数据到MySQL的video表中:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.io.*" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="java.util.*" %>
<jsp:useBean id="dbCon" class="weike.DBConnection" scope="session"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>教师数据处理页面</title>
</head>
<body>
<%
if((String)session.getAttribute("userID")!=null&&(String)session.getAttribute("schoolID")=="2"){
//request.setCharacterEncoding("UTF-8");
//response.setCharacterEncoding("UTF-8");
//response.setContentType("text/html; charset=UTF-8");
MultipartRequest theMultipartRequest=new MultipartRequest(request,"D:\\weike video\\",20*1024*1024,"UTF-8");
Enumeration theEnumeration=theMultipartRequest.getFileNames();
int fileCount=0;
while(theEnumeration.hasMoreElements()){
//fileCount++;
String fieldName=(String)theEnumeration.nextElement();
String fileName=theMultipartRequest.getFilesystemName(fieldName);
String contentType=theMultipartRequest.getContentType(fieldName);
File theFile=theMultipartRequest.getFile(fieldName);

String videoName=theMultipartRequest.getParameter("videoName");
String videoAuthor=theMultipartRequest.getParameter("videoAuthor");
String videoPath=theFile.getAbsolutePath();
String schoolID=theMultipartRequest.getParameter("schoolID");
dbCon.createConnection();
dbCon.updateData(videoName,videoAuthor,videoPath,schoolID);
//out.println(videoName+"<br>");
//out.println(videoAuthor+"<br>");
//out.println(videoPath+"<br>");
//out.println(schoolID+"<br>");

//out.println("属性名称:"+fieldName+"<br>");
//out.println("文件名称:"+fileName+"<br>");
//out.println("文件类型:"+contentType+"<br>");
//out.println("文件路径:"+theFile.getAbsolutePath()+"<br>");
//out.println("===============");
}
out.println("文件上传成功!");

}
%>
</body>
</html>

以下是连接和操作数据库的javaBean:
package weike;
import java.sql.*;
public class DBConnection {
private String userID;
private String password;
private boolean loginCheck=false;
//private String role;
Connection con=null;
Statement st=null;
ResultSet rs=null;
public void setuserID(String userID){
this.userID=userID;
}
public String getuserID(){
try{
//byte b[]=userID.getBytes("iso-8859-1");
//userID=new String(b,"UTF-8");
return userID;
}catch(Exception e){
return userID;
}
}
public void setPassword(String password){
this.password=password;
}
public String getPassword(){
return password;
}
public void createConnection(){
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/weike","ueser","123456");

}catch(Exception e){
e.printStackTrace();
System.out.println("数据库连接失败");
}
}
//test part start..
public ResultSet getResult1(String sql){
try{
st=con.createStatement();
rs=st.executeQuery(sql);
return rs;
}catch(SQLException e){
//System.out.println(e);
e.printStackTrace();
}
return rs;
}
//test part end..
public ResultSet getResult(){
try{
st=con.createStatement();
String sql="select * from user where userID='"+userID+"'and password='"+password+"'";
rs=st.executeQuery(sql);
loginCheck=true;
return rs;

}catch(Exception e){
e.printStackTrace();
loginCheck=false;
}
return rs;
}
public boolean getLoginCheck(){
return loginCheck;
}
public void updateData(String videoName,String videoAuthor,String videoPath,String schoolID){
String sql="insert into video(videoName,videoAuthor,videoPath,SchoolID) values('videoName','videoAuthor','videoPath','schoolID')";
try{
st=null;
//st=con.createStatement();
st.executeUpdate(sql);
}catch(Exception e){
System.out.println(e);
}
}
public void deleteData(String videoID){
String sql="delete from video where videoID='videoID'";
try{
st.executeUpdate(sql);
}catch(Exception e){
System.out.println(e);
}
}
public void close(){
try{
rs.close();
st.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}
}

}
...全文
140 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tomsy2000 2015-01-24
  • 打赏
  • 举报
回复
引用 1 楼 ekekyn 的回复:
//st=con.createStatement(); 怎么注释?
解决了,谢谢
ekekyn 2015-01-23
  • 打赏
  • 举报
回复
//st=con.createStatement(); 怎么注释?

81,092

社区成员

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

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