这是一个bean 吧,编译了吗?编译完成还要重新启动服务器,你在试试

解决方案 »

  1.   

    public void conndb() 
    { }
      

  2.   

    看看吧
    只要把main去掉就是class了,临时改的
    不知道你用不用服务器?
    这个程序要把jdbc三个驱动加进来的
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    public class db{
    String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
    String sConnStr = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mylt";
    String  user="sa";    
    String  password="111";  
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;public db()
    {
    try
    {Class.forName(sDBDriver);
    }
    catch(java.lang.ClassNotFoundException e)
    {
    System.err.println("db(): " + e.getMessage());
    }
    }public void executeInsert(String sql) 
    {
    try
    {
    conn = DriverManager.getConnection(sConnStr,user,password);
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    stmt.executeUpdate(sql);
    stmt.close();
    conn.close();
    }
    catch(SQLException ex)
    {System.err.println("julong.executeinsert:"+ex.getMessage());
    }
    }public ResultSet executeQuery(String sql)
    {
    try
    {
    conn = DriverManager.getConnection(sConnStr,user,password);
    stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);}
    catch(SQLException ex)
    {
    System.err.println("julong.executeQuery:"+ex.getMessage());
    }
    return rs;
    }public boolean executeUpdate(String sql)
    {   
        boolean y=false;
        try {
        conn = DriverManager.getConnection(sConnStr,user,password); 
        stmt = conn.createStatement();
        stmt.executeUpdate(sql);
        y=true;
    stmt.close();
        conn.close();
        
        } 
        catch(SQLException ex) { 
          System.err.println("julong.executeupdate: " + ex.getMessage());
        }
        return y;
    }public void executeDelete(String sql) 
    {
    try
    {
    conn = DriverManager.getConnection(sConnStr,user,password);
    stmt = conn.createStatement();
    stmt.executeUpdate(sql);
    stmt.close();
        conn.close();

    catch(SQLException ex) 
    {
    System.err.println("julong.executeDelete:"+ex.getMessage());
    }
    }public void closeStmt(){
        try{
          stmt.close();
         }
        catch(SQLException e){
          e.printStackTrace();
         }
      }public void closeConn(){
        try{
          conn.close();
         }
        catch(SQLException e){
          e.printStackTrace();
         }
      }
     //处理中文问题的自定义函数 
    public String getcn(String str)//取、
      {
         try
            {
              String temp_p=str;
              byte[] temp_t=temp_p.getBytes("GBK");
              String temp=new String(temp_t,"ISO8859_1");
              return temp;
             }
          catch(Exception e)
             { return "null";}
      }
       public String setcn(String str)//存
      {
         try
            {
              String temp_p=str;
              byte[] temp_t=temp_p.getBytes("ISO8859_1");
              String temp=new String(temp_t);
              return temp;
             }
          catch(Exception e)
             { return "null";}
      }
      
      
      
      public static void main(String[] args)
     {
      
       String sql1="select *  from your table";
       db jl=new db();
       jl.executeUpdate(sql1);
      }
      catch(Exception e){   
          e.printStackTrace();
      }
     }}