当前位置: 技术问答>java相关
谁能给个在页面提交数据并保存到数据库表(拥JAVABEAN)的简单例子,谢谢!
来源: 互联网 发布时间:2015-10-25
本文导语: 谁能给个在页面提交数据并保存到数据库表(拥JAVABEAN)的简单例子,谢谢! | /** * Title: select insert update and delete * Description: select insert update and delete * Copyright: Copyr...
谁能给个在页面提交数据并保存到数据库表(拥JAVABEAN)的简单例子,谢谢!
|
/**
* Title: select insert update and delete
* Description: select insert update and delete
* Copyright: Copyright (c) 2002
* @author luminji
* @version 1.0
*/
import java.sql.*;
public class OpenDba
{
private String query_statement; /*定义sql语句*/
private String param[]; /*查询条件,或者是新的记录*/
private String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
private String sConnStr="jdbc:odbc:ydsp";
private ResultSet result=null;
private Connection conn = null;
private Connection conn1;
public OpenDba(){
try{
Class.forName(sDBDriver);
this.conn1=DriverManager.getConnection(sConnStr,"sa","");
this.conn1.setAutoCommit(false);
this.conn = this.conn1;
}catch(java.lang.Exception e){
System.err.println("OpenDb():"+e.getMessage());}
}
public void setParam(String[] param)
{
this.param=param;
}
public void setQuerystatement(String query_statement)
{
this.query_statement=query_statement;
}
/*获取查询结果*/
public ResultSet getResult()
{
if(query_statement == null || query_statement == "")
System.out.println("SQL语句为空!");
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
* Title: select insert update and delete
* Description: select insert update and delete
* Copyright: Copyright (c) 2002
* @author luminji
* @version 1.0
*/
import java.sql.*;
public class OpenDba
{
private String query_statement; /*定义sql语句*/
private String param[]; /*查询条件,或者是新的记录*/
private String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
private String sConnStr="jdbc:odbc:ydsp";
private ResultSet result=null;
private Connection conn = null;
private Connection conn1;
public OpenDba(){
try{
Class.forName(sDBDriver);
this.conn1=DriverManager.getConnection(sConnStr,"sa","");
this.conn1.setAutoCommit(false);
this.conn = this.conn1;
}catch(java.lang.Exception e){
System.err.println("OpenDb():"+e.getMessage());}
}
public void setParam(String[] param)
{
this.param=param;
}
public void setQuerystatement(String query_statement)
{
this.query_statement=query_statement;
}
/*获取查询结果*/
public ResultSet getResult()
{
if(query_statement == null || query_statement == "")
System.out.println("SQL语句为空!");
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