java问题(急......) 利用JAVA如何保存和导入SQLserver2000的数据库..要源代码..谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是不是用JAVA对数据库进行操作啊. public class DBConnection { //实例化连接类 private static DBConnection instance=null; //实例化连接对象 private static Connection conn=null; /** * 实例边接类 * @return * @throws Exception * @version 1.0, 2007-9-26 下午04:28:02 * @author chengjinxing * @since JDK1.5 */ public static DBConnection getInstance() throws Exception{ if(instance==null){ instance = new DBConnection(); } return instance; } /** * 关闭数据库 * @throws Exception * @version 1.0, 2007-9-27 下午01:16:19 * @author chengjinxing * @since JDK1.5 */ public static void closeConnection() throws Exception{ if(conn!=null&&!conn.isClosed()){ conn.close(); conn = null; } } /** * 建立数据库连接 * @return * @throws Exception * @version 1.0, 2007-9-26 下午04:32:22 * @author chengjinxing * @since JDK1.5 */ public Connection getConnection() throws Exception{ String driverClassName=null,url=null,username=null,password=null; try{ //访问sqlserver driverClassName="net.sourceforge.jtds.jdbc.Driver"; url="jdbc:jtds:sqlserver://localhost/wz"; username="sa"; password="sasa"; if(conn==null){ Class.forName(driverClassName).newInstance(); conn = DriverManager.getConnection(url,username,password); }else{ if(conn.isClosed()){ conn = null; conn = DriverManager.getConnection(url,username,password); } } } catch(Exception e) { e.printStackTrace(); } return conn; } } 向数据库插入一条数据/** * 增加一条记录 * @param model * @return * @throws Exception * @version 1.0, 2007-10-15 下午01:20:31 * @author chengjinxing * @since JDK1.5 */ public boolean insertLoginInfo(LoginModel model) throws Exception { boolean bool = false; int id = this.getNextID(); PreparedStatement ps = null; String sql = "insert into admin(ID,admin,password,quanxian) values(?,?,?,?)"; try{ ps = DBConnection.getInstance().getConnection().prepareStatement(sql); ps.setInt(1, id); ps.setString(2, model.getAdmin()); ps.setString(3, model.getPassword()); ps.setString(4, model.getQuanxian()); bool = ps.execute(); }catch(Exception e){ e.printStackTrace(); }finally{ if(ps!=null){ ps.close(); } DBConnection.closeConnection(); } return !bool; } 从数据库里得到数据/** * 得到所有的用户的信息 * @return List * @throws Exception * @version 1.0, 2007-10-15 下午12:44:15 * @author chengjinxing * @since JDK1.5 */ public List getAllLoginInfo() throws Exception { dataList = new ArrayList(); PreparedStatement ps = null; ResultSet rs = null; String sql = "select * from admin order by ID desc"; try{ ps = DBConnection.getInstance().getConnection().prepareStatement(sql); rs = ps.executeQuery(); while(rs.next()){ model = new LoginModel(); model.setId(Integer.parseInt(rs.getString("ID"))); model.setAdmin(rs.getString("admin")); //model.setManage(Integer.parseInt(rs.getString("manage"))); model.setPassword(rs.getString("password")); model.setQuanxian(rs.getString("quanxian")); dataList.add(model); } }catch(Exception e){ e.printStackTrace(); }finally{ if(rs!=null){ rs.close(); } if(ps!=null){ ps.close(); } DBConnection.closeConnection(); } return dataList; } 我要的是JAVA对SQLserver数据库的备份与恢复?? 备份数据库<%@ page contentType="text/html; charset=GBK" %><%@ page import="java.sql.*" %><% request.setCharacterEncoding("GBK"); try { String DatabaseName = request.getParameter("DataBaseName"); String SavePath = request.getParameter("SavePath"); Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=master;user=sa"); /* * backup database "DataBaseName" to disk="SavePath" * 此语句是用来备份指定的数据库到指定的路径下 * DataBaseName : 要备份的数据库名称 * SavaPath : 备份数据库的路径 * * 数据库备份是将现有的数据库数据备份到备份文件中,当恢复数据库时是恢复备份时的数据 * */ PreparedStatement ps = conn.prepareStatement("backup database ? to disk=?"); ps.setString(1,DatabaseName); ps.setString(2,SavePath); ps.executeUpdate(); ps.close(); conn.close(); out.println("<script>"); out.println("alert('数据库备份成功!');history.back(1);"); out.println("</script>"); } catch (Exception ex) { out.println("备份失败!"); out.println("原因:"+ex.toString()); }%>还原数据库<%@ page contentType="text/html; charset=GBK" %><%@ page import="java.sql.*" %><% request.setCharacterEncoding("GBK"); try { String DatabaseName = request.getParameter("DataBaseName"); String FilePath = request.getParameter("FilePath"); Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=master;user=sa"); /* * restore database "DataBaseName" from disk="FilePath" * 此语句是用来恢复指定数据库的数据 * DataBaseName : 要备份的数据库名称 * SavaPath : 备份文件的路径 * * 数据库备份是将现有的数据库数据备份到备份文件中,当恢复数据库时是恢复备份时的数据 */ PreparedStatement ps = conn.prepareStatement("restore database ? from disk=?"); ps.setString(1,DatabaseName); ps.setString(2,FilePath); ps.executeUpdate(); ps.close(); conn.close(); out.println("<script>"); out.println("alert('数据库恢复成功!');"); out.println("</script>"); } catch (Exception ex) { out.println("恢复失败!"); out.println("原因:"+ex.toString()); }%> tomcat运行数据库操作的servlet文件时出现 HTTP Status 500 错误怎么解决???(急急急急 请问用jsp能实现想 PHP在线升级 那种效果吗? 关于struts2登陆验证的问题? 请教大家一些问题? 请问能不能在使用smartupload组件上传的文件的同时将其路径保存到数据库当中 JFreechart和iText结合使用的问题 javabean编写的问题 ◆请教jsp页面中的缓存问题◆ JSTL标签的问题 java/webservice 大家再帮我看看这是什么错误; 极高分求一正则,进者有分
public class DBConnection {
//实例化连接类
private static DBConnection instance=null;
//实例化连接对象
private static Connection conn=null;
/**
* 实例边接类
* @return
* @throws Exception
* @version 1.0, 2007-9-26 下午04:28:02
* @author chengjinxing
* @since JDK1.5
*/
public static DBConnection getInstance() throws Exception{ if(instance==null){
instance = new DBConnection();
}
return instance;
}
/**
* 关闭数据库
* @throws Exception
* @version 1.0, 2007-9-27 下午01:16:19
* @author chengjinxing
* @since JDK1.5
*/
public static void closeConnection() throws Exception{
if(conn!=null&&!conn.isClosed()){
conn.close();
conn = null;
}
}
/**
* 建立数据库连接
* @return
* @throws Exception
* @version 1.0, 2007-9-26 下午04:32:22
* @author chengjinxing
* @since JDK1.5
*/
public Connection getConnection() throws Exception{
String driverClassName=null,url=null,username=null,password=null;
try{
//访问sqlserver
driverClassName="net.sourceforge.jtds.jdbc.Driver";
url="jdbc:jtds:sqlserver://localhost/wz";
username="sa";
password="sasa";
if(conn==null){
Class.forName(driverClassName).newInstance(); conn = DriverManager.getConnection(url,username,password);
}else{
if(conn.isClosed()){
conn = null;
conn = DriverManager.getConnection(url,username,password);
}
}
} catch(Exception e) {
e.printStackTrace();
}
return conn;
}
}
* 增加一条记录
* @param model
* @return
* @throws Exception
* @version 1.0, 2007-10-15 下午01:20:31
* @author chengjinxing
* @since JDK1.5
*/
public boolean insertLoginInfo(LoginModel model) throws Exception {
boolean bool = false;
int id = this.getNextID();
PreparedStatement ps = null;
String sql = "insert into admin(ID,admin,password,quanxian) values(?,?,?,?)";
try{
ps = DBConnection.getInstance().getConnection().prepareStatement(sql);
ps.setInt(1, id);
ps.setString(2, model.getAdmin());
ps.setString(3, model.getPassword());
ps.setString(4, model.getQuanxian());
bool = ps.execute();
}catch(Exception e){
e.printStackTrace();
}finally{
if(ps!=null){
ps.close();
}
DBConnection.closeConnection();
}
return !bool;
}
* 得到所有的用户的信息
* @return List
* @throws Exception
* @version 1.0, 2007-10-15 下午12:44:15
* @author chengjinxing
* @since JDK1.5
*/
public List getAllLoginInfo() throws Exception { dataList = new ArrayList();
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select * from admin order by ID desc";
try{
ps = DBConnection.getInstance().getConnection().prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
model = new LoginModel();
model.setId(Integer.parseInt(rs.getString("ID")));
model.setAdmin(rs.getString("admin"));
//model.setManage(Integer.parseInt(rs.getString("manage")));
model.setPassword(rs.getString("password"));
model.setQuanxian(rs.getString("quanxian"));
dataList.add(model);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
DBConnection.closeConnection();
}
return dataList;
}
我要的是JAVA对SQLserver数据库的备份与恢复??
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.sql.*" %><%
request.setCharacterEncoding("GBK");
try {
String DatabaseName = request.getParameter("DataBaseName");
String SavePath = request.getParameter("SavePath"); Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=master;user=sa"); /*
* backup database "DataBaseName" to disk="SavePath"
* 此语句是用来备份指定的数据库到指定的路径下
* DataBaseName : 要备份的数据库名称
* SavaPath : 备份数据库的路径
*
* 数据库备份是将现有的数据库数据备份到备份文件中,当恢复数据库时是恢复备份时的数据
*
*/
PreparedStatement ps = conn.prepareStatement("backup database ? to disk=?");
ps.setString(1,DatabaseName);
ps.setString(2,SavePath);
ps.executeUpdate();
ps.close();
conn.close(); out.println("<script>");
out.println("alert('数据库备份成功!');history.back(1);");
out.println("</script>");
}
catch (Exception ex) {
out.println("备份失败!");
out.println("原因:"+ex.toString());
}
%>还原数据库<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.sql.*" %><%
request.setCharacterEncoding("GBK");
try {
String DatabaseName = request.getParameter("DataBaseName");
String FilePath = request.getParameter("FilePath"); Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=master;user=sa"); /*
* restore database "DataBaseName" from disk="FilePath"
* 此语句是用来恢复指定数据库的数据
* DataBaseName : 要备份的数据库名称
* SavaPath : 备份文件的路径
*
* 数据库备份是将现有的数据库数据备份到备份文件中,当恢复数据库时是恢复备份时的数据
*/
PreparedStatement ps = conn.prepareStatement("restore database ? from disk=?");
ps.setString(1,DatabaseName);
ps.setString(2,FilePath);
ps.executeUpdate();
ps.close();
conn.close(); out.println("<script>");
out.println("alert('数据库恢复成功!');");
out.println("</script>");
}
catch (Exception ex) {
out.println("恢复失败!");
out.println("原因:"+ex.toString());
}
%>