WEB开发网
开发学院WEB开发Jsp JavaBean 实例 阅读

JavaBean 实例

 2008-01-05 09:17:24 来源:WEB开发网   
核心提示:package untitled1;import java.sql.*;public class jsp2Bean { PRivate String sample = "Start value"; String strDBDtiver="sun.jdbc.odbc.JdbcOdbcD

  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;
//access 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;
}
}

Tags:JavaBean 实例

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接