一种新的编程思路(中)附:
由于太长:只能这样分开贴
-------------------------------------------------------
核心实现bean
ntDB.java
package dba;
/* newtower存取数据库 */
/* 调用范例
nttest
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@page import="dba.ntDB"%>
<%
ntDB nt = new ntDB();
nt.executeQuery("yw","select * from msgboard_wjm");
out.println( (new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSS")).format(new Date()) );
file://out.println( (new Date()).toString() );
out.println("<br>");
out.println( nt.rowCount );
out.println("<table border=1 >");
for(int i=0;i< nt.rowCount;i++ ){
if(i==0){
out.println("<tr>");
for(int k=0;k< nt.colCount;k++ ){
out.println("<td>");
out.print( nt.fieldName[k] );
out.print("</td>");
}
out.println("</tr>");
}
out.println("<tr>");
for(int j=0;j< nt.colCount;j++ ){
out.println("<td>");
out.println( nt.data[i][j] );
out.println("</td>");
}
out.println("</tr>");
}
out.println("</table>");
%>
*/
import java.util.*;
import java.lang.*;
import java.text.*;
import java.sql.*;
import java.sql.Connection;
import javax.sql.*;
import javax.naming.*;
import javax.transaction.*;
import java.io.*;
import java.net.*;
public class ntDB {
private Connection con;
private String connName;
private Statement statement ;
private ResultSet rs = null ;
private ResultSetMetaData rsmd;
file://额外方法
private Hashtable ht_PinYin=new Hashtable(10);
public int rowCount ;
public int colCount ;
public String[] fieldName ;
public int[] fieldType ;
public int[] columnDisplaySize ;
public String[][] data = null ;
////额外方法
public ntDB() {
rowCount=-1;
colCount=-1;
}
private void getConn(){
try{
Context env=(Context)new InitialContext().lookup("java:comp/env");
DataSource ds = (DataSource) env.lookup("jdbc/"+connName);
con = ds.getConnection();
}catch(Exception e){
e.printStackTrace();
con = null;
}
}
private void closeConn() throws Exception
{
补充:Web开发 , Jsp ,