|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
唉!都是钱闹的1.Swing和.net开发比较------从市场份额看.net开发主要占据大部分的中小型和中型的的桌面开发,原因是它封装了很多工具封装odbc.java
---------------------------------------------
packagebbs;
/*
databaseoperationclass,testbyodbc
Thisjavabeaniswrittenbyzergling
Itismyfirstjavabean:o
version1.01
*/
importjava.sql.*;
importjava.lang.*;
importjava.io.*;
importjava.util.*;
importsun.io.*;
publicclassodbc
{
ConnectionsqlCon;
ResultSetrstSql;
StatementstmS;
StringstrCon;
StringstrSql;
booleanstatus;
longrowcount;
intpage;
intpagesize;
longpagecount;
longfirstrecord;
//connecttothedefaultdatabase
publicbooleanconnect()
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
this.strCon="jdbc:odbc:jspbbs";//replacewithyourdefaultdatabase
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
this.sqlCon=java.sql.DriverManager.getConnection(this.strCon,"sa","");//replacewithyourdefaultdatabaseconnectionconfigureoption
this.status=true;
returntrue;
}
catch(Exceptione)
{
this.status=false;
returnfalse;
}
}
//connecttothecustomdatabase
publicbooleanconnect(StringconName,Stringusername,Stringpassword)
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
this.strCon=conName;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
this.sqlCon=java.sql.DriverManager.getConnection(this.strCon,username,password);
this.status=true;
returntrue;
}
catch(Exceptione)
{
this.status=false;
returnfalse;
}
}
//executesql(insert,update,delete,...)
publicbooleanexecute(Strings)
{
try
{
this.stmS=this.sqlCon.createStatement();
this.stmS.executeUpdate(s);
this.status=true;
returntrue;
}
catch(Exceptione)
{
this.status=false;
returnfalse;
}
}
//querythedatafromdatabase
publicbooleanquery(Strings)
{
try
{
this.rowcount=0;
this.stmS=this.sqlCon.createStatement();
this.rstSql=this.stmS.executeQuery(s);
while(this.nextrecord())
{
this.rowcount++;
}
this.rstSql=this.stmS.executeQuery(s);
this.status=true;
returntrue;
}
catch(Exceptione)
{
this.status=false;
returnfalse;
}
}
//returntherowcount
publiclonggetrowcount()
{
returnthis.rowcount;
}
//returnthepagecount
publiclonggetpagecount()
{
returnthis.pagecount;
}
//returntheresultsetofdata
publicStringgetstring(Strings)
{
try
{
returnthis.rstSql.getString(s);
}
catch(Exceptione)
{
return"notexists";
}
}
publicintgetint(Strings)
{
try
{
returnInteger.parseInt(this.rstSql.getString(s));
}
catch(Exceptione)
{
return0;
}
}
//resultsetmoveforward
publicbooleannextrecord()
{
try
{
returnthis.rstSql.next();
}
catch(Exceptione)
{
returnfalse;
}
}
//setcurrentpage(recallfirst)
publicbooleansetpage(intsize,intno)
{
this.pagesize=size;
this.page=no;
this.pagecount=Math.round((this.rowcount-1)/this.pagesize)+1;
this.firstrecord=this.pagesize*(this.page-1);
try
{
for(inti=0;i<this.firstrecord;i++)
if(!this.nextrecord())break;
returntrue;
}
catch(Exceptione)
{
returnfalse;
}
}
//getstringfromdatabaseandchangeitintochinese
publicStringreadChinese(Strings)
{
try
{
Stringtemp=newString(s.getBytes("GB2312"),"8859_1");
returntemp;
}
catch(Exceptione)
{
returns;
}
}
//writestringtothedatabaseschinesetransform
publicstaticStringwriteChinese(Strings)
{
char[]orig=s.toCharArray();
byte[]dest=newbyte[orig.length];
for(inti=0;i<orig.length;i++)
dest[i]=(byte)(orig[i]&0xFF);
try
{
ByteToCharConvertertoChar=ByteToCharConverter.getConverter("gb2312");
returnnewString(toChar.convertAll(dest));
}
catch(Exceptione)
{
returns;
}
}
//stringssearchandreplace
publicStringreplace(Stringcon,Stringtag,Stringrep){
intj=0;
inti=0;
intk=0;
StringRETU="";
Stringtemp=con;
inttagc=tag.length();
while(i<con.length()){
if(con.substring(i).startsWith(tag)){
temp=con.substring(j,i)+rep;
RETU+=temp;
i+=tagc;
j=i;
}
else{
i+=1;
}
}
RETU+=con.substring(j);
returnRETU;
}
publicVectorlistValue(Stringcon,Stringtag){
intj=0;
inti=0;
intk=0;
Vectorvv=newVector();
Stringtemp=con;
inttagc=tag.length();
while(i<con.length()){
if(con.substring(i).startsWith(tag)){
temp=con.substring(j,i);
vv.addElement(temp);
i+=tagc;
j=i;
}
else{
i+=1;
}
}
vv.addElement(con.substring(j));
returnvv;
}
//filtthehtmlcode&sqlsymbol
publicStringhtmlencode(Strings)
{
try
{
Stringtemp=this.replace(s,"<","<");
temp=this.replace(temp,">",">");
temp=this.replace(temp,"",""");
temp=this.replace(temp,""",""");
temp=this.replace(temp,"","");
temp=this.replace(temp,"
","<br>");
returntemp;
}
catch(Exceptione)
{
returns;
}
}
//returnthestatusoflastoperation
publicbooleangetstatus()
{
returnthis.status;
}
//closeallobject
publicbooleanclose()
{
try
{
if(this.sqlCon!=null)this.sqlCon.close();
if(this.rstSql!=null)this.rstSql.close();
if(this.stmS!=null)this.stmS.close();
this.status=true;
returnfalse;
}
catch(Exceptione)
{
this.status=false;
returntrue;
}
}
}
到时我们不用学struts,不用学spring,不用学Hibernate,只要能把jsf学会了,完全可以替代所有的框架,包括AJAX,都知道AJAX并不是新技术,虽说我没深入学习jsf但我认为jsf应该已经能通过其它技术替代AJAX,实现无缝刷新。 |
|