|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
恰恰证明了java的简单,要不怎么没有通过c/c++来搞个这种框架?js|数据|数据库(转载请说明来历)
From:http://aspfans.yeah.net
必要用到两个程序,jsp文件和数据库操纵的javabean
Select.jsp
<html>
<head>
<title>Selecteverythingfromadatabase</title>
</head>
<body>
<jsp:useBeanid="select"class="DataBaseSelect"scope="request">
</bean>
<%out.print(select.connect());%>
<%out.print(select.select());%>
<p>Formatresults
<%@pageimport="java.util.Vector"%>
<%VectoraResult=select.getResult();%>
<table>
<%for(inti=0;i<aResult.size();i++){%>
<tr>
<td>
<%out.print(aResult.elementAt(i));%>
</td>
</tr>
<%}%>
</table>
</body>
</html>
DataBaseSelect.java
importjava.sql.*;
importjava.util.Vector;
publicclassDataBaseSelect{
privateVectorresult;
publicDataBaseSelect(){
result=newVector();
}//constructorDataBaseSelect
publicStringconnect(){
try{
Class.forName("ajdbcdriver").newInstance();
return"DriverLoaded!";
}catch(ExceptionE){
return"Unabletoloaddriver.";
}
}
publicStringselect(){
try{
ConnectionC=DriverManager.getConnection("databaseconnectionstring");
StatementStmt=C.createStatement();
ResultSetmyResult=Stmt.executeQuery("SELECTacolumnfromatable");
while(myResult.next()){
result.addElement(myResult.getString(1));
}
//Cleanup
myResult.close();
Stmt.close();
C.close();
return"ConnectionSuccess!";
}catch(SQLExceptionE){
return"SQLException:"+E.getMessage();
}
}
/**
*Accessorforresult
**/
publicVectorgetResult(){
returnresult;
}
/**
*Mutatorforresult
**/
publicvoidsetResult(Vectoravector){
result=avector;
}
}//classDataBaseSelect
(转载请说明来历)
From:http://aspfans.yeah.net
你精通任何一门语言就最强大。现在来看,java的市场比C#大,C#容易入手,比较简单,java比较难 |
|