MSsql mssql = new MSsql(SQL_FIND_BY_WORKTIME);
这个是什么?

解决方案 »

  1.   

    少了一个类MSsql,无法编译。
      

  2.   

    我知道,现在那边上不去网了!楼上的,你 自己写一个MSsql类,里面都是空方法,好不好
      

  3.   

    MSSQL到了package com.rmyy;
    import java.sql.*;
    import javax.sql.*;
    import java.io.*;
    import javax.naming.*;public class MSsql{private Connection conn=null;
    private Statement stmt=null;
    private PreparedStatement prepstmt=null;
    /**
     * 
     *
     *
     **/
    public MSsql(){
    try{
      getDataSource();
      stmt=conn.createStatement();}catch(Exception e){
    System.err.println("MSsql init error:"+e);}
     }
       private void getDataSource() {
         try {
           Context ctx = new InitialContext();
           if (ctx == null)
             throw new Exception("Boom - No Context");       DataSource ds =
              (DataSource) ctx.lookup("java:comp/env/jdbc/userDB");
           if (ds != null)
             conn = ds.getConnection();       } catch (Exception e) {
             System.err.println("getDataSource() error: " + e);
           }
      }
     /**
     *
     *
     *
     **/
     public MSsql(String sql){
    try{
      String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=rmyy";
              String user="sa";
              String password="sa";
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
      conn=DriverManager.getConnection(url,user,password);
      prepareStatement(sql);}catch(Exception e){
    System.err.println("MSsql init error:"+e);}}
    public Connection getConnection(){
    return conn;
    }
    public void prepareStatement(String sql) throws SQLException{
    prepstmt=conn.prepareStatement(sql);
    }
        public void setString(int index, String value) throws SQLException {
            prepstmt.setString(index, value);
        } 
        public void setInt(int index, int value) throws SQLException {
            prepstmt.setInt(index, value);
        }
        public void setBoolean(int index, boolean value) throws SQLException {
            prepstmt.setBoolean(index, value);
        }
        public void setDate(int index, Date value) throws SQLException {
            prepstmt.setDate(index, value);
        }
        public void setLong(int index, long value) throws SQLException {
            prepstmt.setLong(index, value);
        }
        public void setFloat(int index, float value) throws SQLException {
            prepstmt.setFloat(index, value);
        }
        public void setBinaryStream(int index, InputStream in, int length) throws SQLException {
            prepstmt.setBinaryStream(index, in, length);
        } 
        public void clearParameters() throws SQLException {
            prepstmt.clearParameters();
        }
        public PreparedStatement getPreparedStatement() {
           return prepstmt;
        }
        public Statement getStatement() {
           return stmt;
        }
        public ResultSet executeQuery(String sql) throws SQLException {
          if (stmt != null){
             return stmt.executeQuery(sql);
          } else
             return null;
         }/**
     * 
     *
     *
     **/
        public ResultSet executeQuery() throws SQLException {
          if (prepstmt != null) {
             return prepstmt.executeQuery();
          } else
             return null;
        }  /**
     * 
     *
     *
     **/
         public void executeUpdate(String sql) throws SQLException {
           if (stmt != null)
           stmt.executeUpdate(sql);
         }
     /**
     * 
     *
     *
     **/
        public void executeUpdate() throws SQLException {
           if (prepstmt != null)
            prepstmt.executeUpdate();
        }/**
     * 
     *
     *
     **/
         public void close() {
            try {
              if (stmt != null) {
                stmt.close();
                stmt = null;
              }
              if (prepstmt != null) {
                prepstmt.close();
                prepstmt = null;
              }
              conn.close();
              conn = null;
            } catch (Exception e) {
              System.err.println("MSsql close error: " + e);
            }
        }