jsp代码修改后在浏览器显示为什么还是原来的代码?怎么修改?
jsp代码修改后在浏览器显示为什么还是原来的代码?怎么修改?jsp如何与数据库(SQLserver2000)建立连接,并进行相关查询,更新操作?(使用纯Java数据库驱动...
jsp代码修改后在浏览器显示为什么还是原来的代码?怎么修改?jsp如何与数据库(SQL server 2000)建立连接,并进行相关查询,更新操作?(使用纯Java数据库驱动程序进行连接的)
展开
2个回答
2013-12-13
展开全部
jsp代码修改后在浏览器显示为什么还是原来的代码?怎么修改?如果你确定改了后没有改变,那么建议你到tomcat webapp下面删除项目。并且重新发布,然后重启tomcat一般就可以了 jsp如何与数据库(SQL server 2000)建立连接,并进行相关查询,更新操作?(使用纯Java数据库驱动程序进行连接的)首先sql2000需要打sp4补丁,项目中需要添加3个jar包 至于怎么获取。我这里写了个通过配置文件配置的方法,你可以参考下 //读取XML文件。注意:web-inf需要有dataSourceConfig.xmlpackage com.bin.struts.util.DBConfig;import java.io.IOException;import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;public class ReadXml {
public static String path; public static DataSourceInfo getDataSourceInfo(){
// a = System.getProperty("user.dir");
//System.out.println("最新路径"+a);
// if(path==null){
// System.out.println("无法获取配置信息");
// return null;
// }else{
// path = path+"WEB-INF\\dataSourceConfig.xml";
// }
//System.out.println("配置文件路径:"+path);
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document doc = null;
try {
doc = db.parse(path);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
DataSourceInfo info = new DataSourceInfo();
NodeList root=doc.getElementsByTagName("dataSource");
for(int i=0;i<root.getLength();i++){
Element node=(Element)root.item(i);
// System.out.println("获取数据库驱动名称:"+node.getElementsByTagName("driverClassName").item(0).getFirstChild().getNodeValue());
info.setDriverClassName(node.getElementsByTagName("driverClassName").item(0).getFirstChild().getNodeValue());
// System.out.println("获取数据库驱动连接:"+node.getElementsByTagName("url").item(0).getFirstChild().getNodeValue());
info.setUrl(node.getElementsByTagName("url").item(0).getFirstChild().getNodeValue());
// System.out.println("获取数据库用户帐号:"+node.getElementsByTagName("username").item(0).getFirstChild().getNodeValue());
info.setUsername(node.getElementsByTagName("username").item(0).getFirstChild().getNodeValue());
// System.out.println("获取数据库用户密码:"+node.getElementsByTagName("password").item(0).getFirstChild().getNodeValue());
info.setPassword(node.getElementsByTagName("password").item(0).getFirstChild().getNodeValue()); }
return info;
}
} //获取数据库连接package com.bin.struts.util.DBConfig;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; public class DBConnection {
public static Connection getConnection(){
//ReadXml info = new ReadXml();
DataSourceInfo temp = ReadXml.getDataSourceInfo();
//String driver=;
//String URL="jdbc:mysql://localhost:3306/ssh";
//String username="root";
//String password="123456";
Connection connection = null;
//System.out.println(temp.getDriverClassName());
try{
Class.forName(temp.getDriverClassName());
connection = DriverManager.getConnection(temp.getUrl(),temp.getUsername(),temp.getPassword());
return connection;
}
catch (SQLException e1){
e1.printStackTrace();
}
catch (ClassNotFoundException e){
e.printStackTrace();
}
return null;
}
public static Connection close(){
ResultSet rs = null;
PreparedStatement pstmt = null;
Statement stmt = null;
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return null;
}} //实体类 package com.bin.struts.util.DBConfig;public class DataSourceInfo {
private String driverClassName;
private String url;
private String username;
private String password;
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}}
//xml文件dataSourceConfig.xml <?xml version="1.0"?><dataSource>
<driverClassName>com.microsoft.jdbc.sqlserver.SQLServerDriver</driverClassName>
<url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=school</url>
<username>sa</username>
<password>123</password>
</dataSource>
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;public class ReadXml {
public static String path; public static DataSourceInfo getDataSourceInfo(){
// a = System.getProperty("user.dir");
//System.out.println("最新路径"+a);
// if(path==null){
// System.out.println("无法获取配置信息");
// return null;
// }else{
// path = path+"WEB-INF\\dataSourceConfig.xml";
// }
//System.out.println("配置文件路径:"+path);
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document doc = null;
try {
doc = db.parse(path);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
DataSourceInfo info = new DataSourceInfo();
NodeList root=doc.getElementsByTagName("dataSource");
for(int i=0;i<root.getLength();i++){
Element node=(Element)root.item(i);
// System.out.println("获取数据库驱动名称:"+node.getElementsByTagName("driverClassName").item(0).getFirstChild().getNodeValue());
info.setDriverClassName(node.getElementsByTagName("driverClassName").item(0).getFirstChild().getNodeValue());
// System.out.println("获取数据库驱动连接:"+node.getElementsByTagName("url").item(0).getFirstChild().getNodeValue());
info.setUrl(node.getElementsByTagName("url").item(0).getFirstChild().getNodeValue());
// System.out.println("获取数据库用户帐号:"+node.getElementsByTagName("username").item(0).getFirstChild().getNodeValue());
info.setUsername(node.getElementsByTagName("username").item(0).getFirstChild().getNodeValue());
// System.out.println("获取数据库用户密码:"+node.getElementsByTagName("password").item(0).getFirstChild().getNodeValue());
info.setPassword(node.getElementsByTagName("password").item(0).getFirstChild().getNodeValue()); }
return info;
}
} //获取数据库连接package com.bin.struts.util.DBConfig;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; public class DBConnection {
public static Connection getConnection(){
//ReadXml info = new ReadXml();
DataSourceInfo temp = ReadXml.getDataSourceInfo();
//String driver=;
//String URL="jdbc:mysql://localhost:3306/ssh";
//String username="root";
//String password="123456";
Connection connection = null;
//System.out.println(temp.getDriverClassName());
try{
Class.forName(temp.getDriverClassName());
connection = DriverManager.getConnection(temp.getUrl(),temp.getUsername(),temp.getPassword());
return connection;
}
catch (SQLException e1){
e1.printStackTrace();
}
catch (ClassNotFoundException e){
e.printStackTrace();
}
return null;
}
public static Connection close(){
ResultSet rs = null;
PreparedStatement pstmt = null;
Statement stmt = null;
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return null;
}} //实体类 package com.bin.struts.util.DBConfig;public class DataSourceInfo {
private String driverClassName;
private String url;
private String username;
private String password;
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}}
//xml文件dataSourceConfig.xml <?xml version="1.0"?><dataSource>
<driverClassName>com.microsoft.jdbc.sqlserver.SQLServerDriver</driverClassName>
<url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=school</url>
<username>sa</username>
<password>123</password>
</dataSource>
2013-12-13
展开全部
用java文件写数据库连接。和增删改查的方法
用jsp页面来调用方法。执行操作!!
用jsp页面来调用方法。执行操作!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询