CSDN博客

img flyying

exeQuery

发表于2004/10/18 11:00:00  907人阅读

package zpxx;
import java.sql.*;
import java.util.*;
import java.io.*;
import zpxx.*;

public class exeQuery{
 public boolean Query(String strSQL) throws SQLException{
  Connection conn = null;
  DBConnectionManager connMgr = DBConnectionManager.getInstance();
  conn = connMgr.getConnection("zpxx");
  Statement stmt = null;
  try{
   stmt = conn.createStatement();
   strGBK toGBK = new strGBK();
   stmt.executeUpdate(toGBK.isoTOgbk(strSQL));
   //stmt.executeUpdate(strSQL);
   stmt.close();
   connMgr.freeConnection("zpxx",conn);
   connMgr.release();
  }
  catch(Exception e){
   stmt.close();
   connMgr.freeConnection("zpxx",conn);
   connMgr.release();
   return false;
  }
  return true;
 }
 public boolean arrayQuery(String[] strSQL) throws SQLException{
  Connection conn = null;
  DBConnectionManager connMgr = DBConnectionManager.getInstance();
  conn = connMgr.getConnection("zpxx");
  Statement stmt = null;
  try{
   stmt = conn.createStatement();
   strGBK toGBK = new strGBK();
   conn.setAutoCommit(false);
   for(int iStart = 0;iStart < strSQL.length;iStart++)
    stmt.executeUpdate(toGBK.isoTOgbk(strSQL[iStart]));
   conn.commit();
   stmt.close();
   connMgr.freeConnection("zpxx",conn);
   connMgr.release();
  }
  catch(Exception e){
   conn.rollback();
   stmt.close();
   connMgr.freeConnection("zpxx",conn);
   connMgr.release();   
   return false;
  }
  return true;
 }
 public String[][] arrayTable(String strSQL) throws SQLException{
  String[][] rString;
  int iCount = 0;
  Connection conn = null;
  DBConnectionManager connMgr = DBConnectionManager.getInstance();
  conn = connMgr.getConnection("zpxx");
  Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
  ResultSet rs = stmt.executeQuery(strSQL);
  ResultSetMetaData rColNum = rs.getMetaData();
  if(rs.last())
   iCount = rs.getRow();
  //System.out.println("i= " + iCount + "    r=" + rColNum.getColumnCount());
  rString = new String[iCount][rColNum.getColumnCount()];
  rs.beforeFirst();
  int iRow = 0;
  int iCol = 0;
  while(rs.next()){
   for(iCol = 0;iCol < rColNum.getColumnCount();iCol++)
    rString[iRow][iCol] = rs.getString(iCol + 1);
   iRow++;
  }
  rs.close();
  stmt.close();
  connMgr.freeConnection("zpxx",conn);
  connMgr.release();
  return rString;
 }
 
    public static String[] split(String s, String separator)
    {
        if(s == null)
            throw new NullPointerException("source String cannot be null");
        if(separator == null)
            throw new NullPointerException("separator cannot be null");
        if(separator.length() == 0)
            throw new IllegalArgumentException("separator cannot be empty");

        ArrayList buffer = new ArrayList();
       
        int start = 0;
        int end = s.indexOf(separator);
        while(end != -1)
        {
            buffer.add(s.substring(start, end));
            start = end + separator.length();
            end = s.indexOf(separator, start);
        }
        buffer.add(s.substring(start, s.length()));

        return (String[]) buffer.toArray(new String[0]);
    }
   
  /*
    public String rce(String parentStr,String ch,String rep)
 {
 int i = parentStr.indexOf(ch);
 StringBuffer sb = new StringBuffer();
 if (i == -1){
  return parentStr;
 }
  sb.append(parentStr.substring(0,i) + rep);
 if (i+ch.length() < parentStr.length()) {
 sb.append(rce(parentStr.substring(i+ch.length(),parentStr.length()),ch,rep));
 }
 return sb.toString();
 }
*/
 public String AddBr(String Content)
 {
   if (Content == null) return "";
     //String makeContent=new String();
     //StringTokenizer strToken=new StringTokenizer(Content,"/n");
     //while(strToken.hasMoreTokens())
     //{
        // makeContent=makeContent+"<br>"+strToken.nextToken();
     //}

  char[] cc=Content.toCharArray();
  String bb="";
  for(int i=0;i<cc.length;i++)
  {
   System.out.println(Character.digit(cc[i],16));
   if(Character.isSpaceChar(cc[i]))
   {
    bb+="&nbsp;";
   }
   else if(cc[i]=='/r' && i<cc.length-1 && cc[i+1]=='/n')
   {
    bb+="<br>";
   }
   else
   {
    bb+=cc[i];
   }
  }
   return bb;
   }
   
 

    public static void main(String args[]){
     exeQuery eQry1 = new exeQuery();
 // String[] result = eQry1.split("a.gif", ".");
 // for(int i=0;i<result.length;i++){
 // System.out.println(result[i]);
     String sql="select * from project1";
  String[][] rs1=eQry1.arrayTable(sql);  
  for(int i=0;i<rs1.length;i++){
   System.out.println(rs1[i][1]);
  }
  
 }


}

阅读全文
0 0

相关文章推荐

img
取 消
img