|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
轮性能微软曾做过一个例子,就是同一个项目用java和.net来作,结果开发周期,.net是java的一半,性能java是.net的十分之一,代码量java是.net的三倍。呵呵,这说明了什么,.net的全方位比java好。但是有的人说.net不能跨平台,这个问题我和我同学曾讨论过,都认为微软的.net很可能早都可以跨平台了,但是微软为了保护他们的操作系统,所以才没有推出跨平台的.net,只是推出了跨语言的.net,js|oracle|分页packagecom.cwbnig;
importjava.sql.Connection;
importjava.sql.SQLException;
importjavax.sql.DataSource;
importjavax.naming.Context;
importjavax.naming.InitialContext;
importjavax.naming.NamingException;
publicclassDatabaseConn
{
publicDatabaseConn()
{
}
publicstaticsynchronizedConnectiongetConnection()throwsException
{
Connectionconn=null;
try
{
ContextinitCtx=newInitialContext();
ContextenvCtx=(Context)initCtx.lookup("java:comp/env");
DataSourceds=(DataSource)envCtx.lookup("jdbc/jspdev");
returnds.getConnection();
}
catch(SQLExceptione)
{
throwe;
}
catch(NamingExceptione)
{
throwe;
}
}
}
packagecom.cwbnig;
importjava.sql.*;
importjava.util.Vector;
publicclassOperateDB
{
privateConnectionconn=null;
privateStatementstmt=null;
PreparedStatementpstmt=null;
CallableStatementcstmt=null;
privateResultSetrs=null;
privateResultSetMetaDatarsmd=null;
privateStringstrsql="";
publicOperateDB()
{
try
{
conn=DatabaseConn.getConnection();
}
catch(Exceptione)
{
System.out.println("Error:com.cwbnig.OperateDB:StructureMethod");
}
}
publicConnectiongetConnection()throwsSQLException
{
returnthis.conn;
}
publicResultSetexecuteQuery(Stringsql)throwsSQLException
{
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
returnstmt.executeQuery(sql);
}
publicResultSetlistDataFromMSSQL(intcurpage,intpagesize,Stringtablename,Stringsid,Stringcon,Stringorder)throwsSQLException
{
intSELECTNUM=(curpage-1)*pagesize+1;
if(order.equalsIgnoreCase("asc"))
{
Stringmin="SELECTMAX("+sid+")ASidFROM(SELECTTOP"+SELECTNUM+""+sid+"FROM"+tablename+"ORDERBY"+sid+"ASC)tbl";
strsql="SELECTTOP"+pagesize+"*FROM"+tablename+"WHERE"+sid+">="+min+con+"ORDERBY"+sid+"ASC";
}
else
{
Stringmax="SELECTMIN("+sid+")ASidFROM(SELECTTOP"+SELECTNUM+""+sid+"FROM"+tablename+"ORDERBY"+sid+"DESC)tbl";
strsql="SELECTTOP"+pagesize+"*FROM"+tablename+"WHERE"+sid+"<="+max+con+"ORDERBY"+sid+"DESC";
}
returnthis.executeQuery(strsql);
}
publicResultSetlistDataFromMySQL(intcurpage,intpagesize,Stringtablename,Stringsid,Stringcon,Stringorder)throwsSQLException
{
intSELECTNUM=(curpage-1)*pagesize;
if(order.equalsIgnoreCase("asc"))
{
strsql="SELECT*FROM"+tablename+con+"ORDERBY"+sid+"ASCLIMIT"+SELECTNUM+","+pagesize;
}
else
{
strsql="SELECT*FROM"+tablename+con+"ORDERBY"+sid+"DESCLIMIT"+SELECTNUM+","+pagesize;
}
returnthis.executeQuery(strsql);
}
publicResultSetlistDataFromOracle(intcurpage,intpagesize,Stringtablename,Stringsid,Stringcon,Stringorder)throwsSQLException
{
intSELECTNUM=(curpage-1)*pagesize+2;
if(order.equalsIgnoreCase("asc"))
{
Stringmin="SELECTMAX("+sid+")ASSIDFROM(SELECT"+sid+"FROM"+tablename+"WHEREROWNUM<"+SELECTNUM+"ORDERBY"+sid+"ASC)TBL";
strsql="SELECT*FROM"+tablename+"WHERE"+sid+">=("+min+")ANDROWNUM<"+(pagesize+1)+con+"ORDERBY"+sid+"ASC";
}
else
{
Stringmax="SELECTMIN("+sid+")ASSIDFROM(SELECT"+sid+"FROM"+tablename+"WHEREROWNUM<"+SELECTNUM+"ORDERBY"+sid+"DESC)TBL";
strsql="(SELECT*FROM"+tablename+"WHERE"+sid+"<=("+max+")ORDERBY"+sid+"DESC)TBL2";
strsql="SELECT*FROM"+strsql+"WHEREROWNUM<"+(pagesize+1)+con;
}
returnthis.executeQuery(strsql);
}
publicVectorgetDataFromMSSQL(intcurpage,intpagesize,Stringtablename,Stringsid,Stringcon,Stringorder)throwsException
{
Vectorv=newVector();
rs=this.listDataFromMSSQL(curpage,pagesize,tablename,sid,con,order);
rsmd=rs.getMetaData();
intcolnum=rsmd.getColumnCount();
while(rs.next())
{
Object[]obj=newObject[colnum];
for(inti=0;i<colnum;i++)
{
obj[i]=newString(this.getCol(rs,rsmd.getColumnType(i+1),i+1));
}
v.add(obj);
}
stmt.close();
rs.close();
conn.close();
returnv;
}
publicVectorgetDataFromMySQL(intcurpage,intpagesize,Stringtablename,Stringsid,Stringcon,Stringorder)throwsException
{
Vectorv=newVector();
rs=this.listDataFromMySQL(curpage,pagesize,tablename,sid,con,order);
rsmd=rs.getMetaData();
intcolnum=rsmd.getColumnCount();
while(rs.next())
{
Object[]obj=newObject[colnum];
for(inti=0;i<colnum;i++)
{
obj[i]=newString(this.getCol(rs,rsmd.getColumnType(i+1),i+1));
}
v.add(obj);
}
stmt.close();
rs.close();
conn.close();
returnv;
}
publicVectorgetDataFromOracle(intcurpage,intpagesize,Stringtablename,Stringsid,Stringcon,Stringorder)throwsException
{
Vectorv=newVector();
rs=this.listDataFromOracle(curpage,pagesize,tablename,sid,con,order);
rsmd=rs.getMetaData();
intcolnum=rsmd.getColumnCount();
while(rs.next())
{
Object[]obj=newObject[colnum];
for(inti=0;i<colnum;i++)
{
obj[i]=newString(this.getCol(rs,rsmd.getColumnType(i+1),i+1));
}
v.add(obj);
}
stmt.close();
rs.close();
conn.close();
returnv;
}
publicStringgetCol(ResultSetrs,inttype,intcolNum)throwsException
{
Stringret="";
switch(type)
{
case(1):ret=rs.getString(colNum);break;
case(2):ret=rs.getString(colNum);break;
case(4):ret=String.valueOf(rs.getInt(colNum));break;
case(5):ret=String.valueOf(rs.getInt(colNum));break;
case(6):ret=String.valueOf(rs.getFloat(colNum));break;
case(8):ret=String.valueOf(rs.getDouble(colNum));break;
case(12):ret=rs.getString(colNum);break;
default:ret="notknow";
}
returnret;
}
publicObject[]getColName(Stringtablename)throwsException
{
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery("SELECT*FROM"+tablename+"WHEREROWNUM<2");
rsmd=rs.getMetaData();
intcolnum=rsmd.getColumnCount();
Object[]obj=newObject[colnum];
for(inti=0;i<colnum;i++)
{
obj[i]=rsmd.getColumnName(i+1);
}
returnobj;
}
publicintgetRowCount(Stringtablename)throwsSQLException
{
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
strsql="SELECTCOUNT(*)ASCOUNTFROM"+tablename;
rs=stmt.executeQuery(strsql);
if(rs.next())
{
returnrs.getInt(1);
}
else
{
return0;
}
}
publicintgetRowCount(ResultSetrs)throwsSQLException
{
introwCount=0;
rs.last();
rowCount=rs.getRow();
rs.beforeFirst();
returnrowCount;
}
publicintexecuteUpdate(Stringsql)throwsSQLException
{
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
returnstmt.executeUpdate(sql);
}
publicint[]executeUpdateBatch(String[]sqls)throwsSQLException
{
conn.setAutoCommit(false);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
try
{
for(inti=0;i<sqls.length;i++)
{
stmt.addBatch(sqls[i]);
}
int[]updateCounts=stmt.executeBatch();
conn.commit();
conn.setAutoCommit(true);
returnupdateCounts;
}
catch(SQLExceptione)
{
conn.rollback();
throwe;
}
}
publicPreparedStatementprepareStatement(Stringsql)throwsSQLException
{
pstmt=conn.prepareStatement(sql);
returnpstmt;
}
publicCallableStatementcallableStatement(Stringsql)throwsSQLException
{
cstmt=conn.prepareCall(sql);
returncstmt;
}
publicvoidsetAutoCommit(booleans)throwsSQLException
{
conn.setAutoCommit(s);
}
publicvoidcommit()throwsSQLException
{
conn.commit();
}
publicvoidrollback()throwsSQLException
{
conn.rollback();
}
publicvoidclose()throwsSQLException
{
if(stmt!=null)
{
stmt.close();
stmt=null;
}
if(conn!=null)
{
conn.close();
conn=null;
}
}
}
<%@pagecontentType="text/html;charset=gb2312"language="java"errorPage="errorinfo.jsp"%>
<html>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<title>testOracle</title>
</head>
<body>
<jsp:useBeanid="operatedb"scope="page"class="com.cwbnig.OperateDB"/>
<%
Object[]obj=null;
obj=operatedb.getColName("TBL_STRUCTS");
for(inttemp=0;temp<obj.length;temp++)
{
out.println(obj[temp]);
}
out.println("<br>");
java.util.Vectorv=operatedb.getDataFromOracle(1,10,"TBL_STRUCTS","SID","","desc");
java.util.Enumeratione=v.elements();
while(e.hasMoreElements())
{
obj=(Object[])e.nextElement();
for(inti=0;i<obj.length;i++)
{
out.println(obj[i]);
}
out.print("<br>");
}
%>
</table>
<br>
<ahref="testOracle.do?forward=bdgk">testOracle.do?forward=bdgk</a>
</body>
</html>
微软什么都提供了。你可以试想一下,如果你是新手,你是希望你点一下按钮程序就能运行那,还是想自己一点一点的组织结构,然后打包发部,调错再打包...... |
|