javabean连接mysql数据库,使用JavaBean不能插入MySQL数据库,该怎么解决

使用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();

怎么注释?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值