当前位置: 技术问答>java相关
菜鸟刚学jsp,刚知道怎么和sql server2000的数据库相连并显示所有数据!谁能给我一段在sql server2000下添加,删除,更改的代码,菜鸟感
来源: 互联网 发布时间:2015-09-11
本文导语: 给我发到邮箱里也行,pjwanglong2000@sohu.com | QueryBean.java: pacakage operate_db; /** * Title: select insert update and delete * Description: select insert update and delete * Copyright: Copyright...
给我发到邮箱里也行,pjwanglong2000@sohu.com
|
QueryBean.java:
pacakage operate_db;
/**
* Title: select insert update and delete
* Description: select insert update and delete
* Copyright: Copyright (c) 2001
* @author Lci21
* @version 1.0
*/
import java.sql.*;
public class QueryBean
{
public String query_statement; /*定义sql语句*/
public String param[]; /*查询条件,或者是新的记录*/
public ResultSet result=null;
public Connection conn;
public void setParam(String[] param)
{
this.param=param;
}
public void setQuerystatement(String query_statement)
{
this.query_statement=query_statement;
}
public void setConnection(String driverName,String jdbcURL,String username,String passwd) throws Exception
{
Connection conn1;
Class.forName(driverName);
conn1=DriverManager.getConnection(jdbcURL,username,passwd);
conn1.setAutoCommit(false);
this.conn = conn1;
}
/*获取查询结果*/
public ResultSet getResult()
{
try
{
PreparedStatement select_stm=conn.prepareStatement(query_statement,java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
if (param!=null)
for(int i=0;i
pacakage operate_db;
/**
* Title: select insert update and delete
* Description: select insert update and delete
* Copyright: Copyright (c) 2001
* @author Lci21
* @version 1.0
*/
import java.sql.*;
public class QueryBean
{
public String query_statement; /*定义sql语句*/
public String param[]; /*查询条件,或者是新的记录*/
public ResultSet result=null;
public Connection conn;
public void setParam(String[] param)
{
this.param=param;
}
public void setQuerystatement(String query_statement)
{
this.query_statement=query_statement;
}
public void setConnection(String driverName,String jdbcURL,String username,String passwd) throws Exception
{
Connection conn1;
Class.forName(driverName);
conn1=DriverManager.getConnection(jdbcURL,username,passwd);
conn1.setAutoCommit(false);
this.conn = conn1;
}
/*获取查询结果*/
public ResultSet getResult()
{
try
{
PreparedStatement select_stm=conn.prepareStatement(query_statement,java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
if (param!=null)
for(int i=0;i