使用JavaBean不能插入MySQL数据库
这是JSP页面,参数都能正确传过来,就是不能插入数据到MySQL的video表中:
pageEncoding="UTF-8"%>
html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
教师数据处理页面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+"
");
//out.println(videoAuthor+"
");
//out.println(videoPath+"
");
//out.println(schoolID+"
");
//out.println("属性名称:"+fieldName+"
");
//out.println("文件名称:"+fileName+"
");
//out.println("文件类型:"+contentType+"
");
//out.println("文件路径:"+theFile.getAbsolutePath()+"
");
//out.println("===============");
}
out.println("文件上传成功!");
}
%>
以下是连接和操作数据库的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();
}
}
}
------解决思路----------------------
//st=con.createStatement();
怎么注释?