当前位置: 技术问答>java相关
为什么我的数据库更新了,网页没有更新的?
来源: 互联网 发布时间:2015-10-17
本文导语: //AddBook.html book id: book name: book description: book pirce: book quantity: //AddBook.jsp All Book //Book.class package book; import java.sql.*; import java.util.*; public class Book { public Book() { } public Book(String i...
//AddBook.html
book id:
book name:
book description:
book pirce:
book quantity:
//AddBook.jsp
All Book
//Book.class
package book;
import java.sql.*;
import java.util.*;
public class Book
{
public Book()
{
}
public Book(String id,String name,String des,float price,int qty,int leftqty)
{
this.id =id;
this.name =name;
this.des =des;
this.price =price;
this.qty =qty;
this.leftqty =leftqty;
}
public String operateBook(String operation)
{
String strReturn="";
if (operation.equals("") || operation=="")
return "what operation will u select !!";
if (operation.equals("insert"))
{
sql="insert into book values ('" + this.id + "',";
sql=sql+ "'" + this.name + "',";
sql=sql+ "'" + this.des + "',";
sql=sql+ "'" + this.qty + "',";
sql=sql+ "'" + this.leftqty + "',";
sql=sql+ "'" + this.price + "')";
}
else if (operation.equals("update"))
{
sql="update book set name='" + this.name +"',";
sql =sql + "des='" + this.des + "',";
sql =sql + "qty='" + this.qty + "',";
sql =sql + "leftqty='" + this.leftqty + "',";
sql =sql + "price='" + this.price + "' " ;
sql =sql + "where id='" + this.id + "'";
}
else if (operation.equals("delete"))
{
sql ="delete from book where id = '" + this.id + "'";
}
else if (operation.equals("select") )
{
if (this.id.equals("") ||this.id =="")
;
else
sql = "select id,name,des,price,qty,leftqty from book where id ='" + this.id + "'";
}
ConDB conDB=new ConDB();
conDB.connectToDB() ;
this.con =conDB.getCon() ;
this.st =conDB.getSt() ;
try
{
if (operation.equals("select") )
{
rs=st.executeQuery(sql) ;
while(rs.next() )
{
this.id=rs.getString("id") ;
this.name =rs.getString("name") ;
this.des =rs.getString("des") ;
this.price =rs.getFloat("price") ;
this.qty =rs.getInt("qty") ;
}
strReturn=sql+ " and find " +this.name ;
}
else
strReturn= sql + st.executeUpdate(sql);
conDB.Close() ;
return strReturn;
}
catch (Exception e)
{
return "fail " + sql ;
}
}
public void setId(String id)
{
this.id =id;
}
public String getId()
{
return this.id ;
}
public void setName(String name)
{
this.name =name;
}
public String getName()
{
return this.name ;
}
public void setDes(String des)
{
this.des =des;
}
public String getDes()
{
return this.des ;
}
public void setPrice(float price)
{
this.price =price;
}
public float getPrice()
{
return this.price ;
}
public void setQty(int qty)
{
this.qty =qty;
}
public int getQty()
{
return this.qty ;
}
public void setLeftQty(int leftqty)
{
this.leftqty =leftqty;
}
public int getLeftQty()
{
return this.leftqty ;
}
private String id ="";
private String name="";
private String des="";
private int qty=0;
private int leftqty=0;
private float price =0;
private Connection con=null;
private Statement st=null;
private String sql="";
private ResultSet rs=null;
//conDB.class
package book;
import java.util.*;
import java.sql.*;
public class ConDB
{
public ConDB()
{
}
public String connectToDB()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver" ) ;
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://MARUSHO-SERVER1;DatabaseName=test","sa","123456") ;
st=con.createStatement() ;
return "success connecting to DB!!!";
}
catch(Exception e)
{
return "fail connecting to DB!!" + e.getMessage() ;
}
}
public String Close()
{
try
{
if (st!=null)
st.close() ;
if (con!=null)
con.close() ;
return "success disconnecting toDB!!!";
}
catch(Exception e)
{
return "fail disconnecting to DB !!"+ e.getMessage() ;
}
}
public Connection getCon()
{
return this.con;
}
public Statement getSt()
{
return this.st;
}
private Connection con=null;
private Statement st=null;
}
//AllBook.jsp
book name
book description
book price
book quantity
left book
我在JB7(安装好后没有修改配置)中运行了AddBook.jsp后数据库中更新了,在AllBook.jsp中没有更新的?
book id:
book name:
book description:
book pirce:
book quantity:
//AddBook.jsp
All Book
//Book.class
package book;
import java.sql.*;
import java.util.*;
public class Book
{
public Book()
{
}
public Book(String id,String name,String des,float price,int qty,int leftqty)
{
this.id =id;
this.name =name;
this.des =des;
this.price =price;
this.qty =qty;
this.leftqty =leftqty;
}
public String operateBook(String operation)
{
String strReturn="";
if (operation.equals("") || operation=="")
return "what operation will u select !!";
if (operation.equals("insert"))
{
sql="insert into book values ('" + this.id + "',";
sql=sql+ "'" + this.name + "',";
sql=sql+ "'" + this.des + "',";
sql=sql+ "'" + this.qty + "',";
sql=sql+ "'" + this.leftqty + "',";
sql=sql+ "'" + this.price + "')";
}
else if (operation.equals("update"))
{
sql="update book set name='" + this.name +"',";
sql =sql + "des='" + this.des + "',";
sql =sql + "qty='" + this.qty + "',";
sql =sql + "leftqty='" + this.leftqty + "',";
sql =sql + "price='" + this.price + "' " ;
sql =sql + "where id='" + this.id + "'";
}
else if (operation.equals("delete"))
{
sql ="delete from book where id = '" + this.id + "'";
}
else if (operation.equals("select") )
{
if (this.id.equals("") ||this.id =="")
;
else
sql = "select id,name,des,price,qty,leftqty from book where id ='" + this.id + "'";
}
ConDB conDB=new ConDB();
conDB.connectToDB() ;
this.con =conDB.getCon() ;
this.st =conDB.getSt() ;
try
{
if (operation.equals("select") )
{
rs=st.executeQuery(sql) ;
while(rs.next() )
{
this.id=rs.getString("id") ;
this.name =rs.getString("name") ;
this.des =rs.getString("des") ;
this.price =rs.getFloat("price") ;
this.qty =rs.getInt("qty") ;
}
strReturn=sql+ " and find " +this.name ;
}
else
strReturn= sql + st.executeUpdate(sql);
conDB.Close() ;
return strReturn;
}
catch (Exception e)
{
return "fail " + sql ;
}
}
public void setId(String id)
{
this.id =id;
}
public String getId()
{
return this.id ;
}
public void setName(String name)
{
this.name =name;
}
public String getName()
{
return this.name ;
}
public void setDes(String des)
{
this.des =des;
}
public String getDes()
{
return this.des ;
}
public void setPrice(float price)
{
this.price =price;
}
public float getPrice()
{
return this.price ;
}
public void setQty(int qty)
{
this.qty =qty;
}
public int getQty()
{
return this.qty ;
}
public void setLeftQty(int leftqty)
{
this.leftqty =leftqty;
}
public int getLeftQty()
{
return this.leftqty ;
}
private String id ="";
private String name="";
private String des="";
private int qty=0;
private int leftqty=0;
private float price =0;
private Connection con=null;
private Statement st=null;
private String sql="";
private ResultSet rs=null;
//conDB.class
package book;
import java.util.*;
import java.sql.*;
public class ConDB
{
public ConDB()
{
}
public String connectToDB()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver" ) ;
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://MARUSHO-SERVER1;DatabaseName=test","sa","123456") ;
st=con.createStatement() ;
return "success connecting to DB!!!";
}
catch(Exception e)
{
return "fail connecting to DB!!" + e.getMessage() ;
}
}
public String Close()
{
try
{
if (st!=null)
st.close() ;
if (con!=null)
con.close() ;
return "success disconnecting toDB!!!";
}
catch(Exception e)
{
return "fail disconnecting to DB !!"+ e.getMessage() ;
}
}
public Connection getCon()
{
return this.con;
}
public Statement getSt()
{
return this.st;
}
private Connection con=null;
private Statement st=null;
}
//AllBook.jsp
book name
book description
book price
book quantity
left book
我在JB7(安装好后没有修改配置)中运行了AddBook.jsp后数据库中更新了,在AllBook.jsp中没有更新的?
|
你将网页设置成不在客户端缓存试试.
|
估计服务器段有缓存吧,没有在数据库更新后再去查询,还用了原来的页面,看看tomcat的配置是不是能改一下。
|
这是jsp的老问题了,你把tomcat重启,把网页的缓冲删除,再打开一个新的网页试试吧,应该就可以了!
|
有时候需要删除它的_jsp目录下编译过的文件
|
应该是缓存问题
删除
tomcatwork下的文件
删除
tomcatwork下的文件