JavaBean 实例

发表于:2007-06-22来源:作者:点击数: 标签:
package untitled1; import java . sql .*; public class Jsp2Bean { private String sample = "Start value"; String strDBDtiver="sun.jdbc.odbc.JdbcOdbcDriver"; String strConn ="jdbc:odbc:unititled1"; Connection conn=null; ResultSet rs = null; /

   
  package untitled1;
import java.sql.*;
public class Jsp2Bean {
private String sample = "Start value";
String strDBDtiver="sun.jdbc.odbc.JdbcOdbcDriver";
String strConn ="jdbc:odbc:unititled1";

Connection conn=null;
ResultSet rs = null;
//Aclearcase/" target="_blank" >ccess sample property
public String getSample() {
return sample;
}
//Access sample property
public void setSample(String newValue) {
if (newValue!=null) {
sample = newValue;
}
}
public Jsp2Bean(){
try{
Class.forName(strDBDtiver);
}
catch(java.lang.ClassNotFoundException e){
System.out.println("DataBase Open Error : " + e.getMessage());
}
}
public ResultSet exeCuteQuery(String strSQL){
rs=null;
try{
conn = DriverManager.getConnection(strConn);
Statement stmt = conn.createStatement();
rs= stmt.executeQuery(strSQL);
}
catch(java.sql.SQLException ex){
System.out.println("SQL RUN ERROR : " + ex.getMessage());
}
return rs;
}
}

原文转自:http://www.ltesting.net