Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hudson.plugins.dbcharts;
  
  
 import java.util.List;
 
 
 
 
 
 public abstract class JDBCConnection /*implements Describable<JDBCConnection>, ExtensionPoint*/ implements Serializable{
     
     private static final long serialVersionUID = -7258724749798334055L;
     
     public final String name;
     public final String url;
     public final String user;
     public final String passwd;
     
     public JDBCConnection(String nameString urlString userString passwd )
     {
         super();
         this. = name;
         this. = url;
         this. = user;
         this. = passwd;
     }
     
     public JDBCConnectionJSONObject o )
     {
         this. = o.getString"name" );
         this. = o.getString"url" );
         this. = o.getString"user" );
         this. = o.getString"passwd" );
     }
    
     public List<StringgetDrivers(){
         Enumeration<Drivere=DriverManager.getDrivers();
         List<Stringres=new LinkedList<String>();
         while(e.hasMoreElements()){
             res.adde.nextElement().getClass().getCanonicalName() );
         }
         return res;
     }
     
     public abstract String getDriver();
     
     public abstract static class JDBCConnectionDescriptor<T extends Describable<T>> extends Descriptor<T>{
                 
         public FormValidation doCheckName(@QueryParameter String valuethrows IOExceptionServletException {
             if(value.length()==0)
                 return FormValidation.error("Please set a name");
             if(value.length()<4)
                 return FormValidation.warning("Isn't the name too short?");
             return FormValidation.ok();
         }      
         
         public void doTestConnection(StaplerRequest reqStaplerResponse rsp,
                                      @QueryParameter("driver"final String driver
                                      @QueryParameter("url"final String url,
                                      @QueryParameter("user"final String user,
                                      @QueryParameter("passwd"final String passwd
                                      ) throws IOExceptionServletException {
             try
             {            
                 Class<?> dc=Class.forNamedriver );                
                     
                 Driver d=(Driverdc.newInstance();
                 if(!d.acceptsURLurl )){
                     FormValidation.error("Driver: "+driver+" does not accept:"+url).generateResponsereqrspthis);                    
                 }else{     
                     DriverManager.getConnectionurluserpasswd );
                     FormValidation.ok("Connection OK").generateResponsereqrspthis);
                 }                
             }
             catch ( SQLException e )
             {
                 FormValidation.error(e.getMessage()).generateResponsereqrspthis);
             }
             catch ( ClassNotFoundException e )
             {
                FormValidation.error("Class not found:"+e.getMessage()).generateResponsereqrspthis);
            }
            catch ( InstantiationException e )
            {
                FormValidation.error("Cannot create instance of:"+e.getMessage()).generateResponsereqrspthis);
            }
            catch ( IllegalAccessException e )
            {
                FormValidation.error(e.getMessage()).generateResponsereqrspthis);
            }       
        }
    }
    
    public Connection createConnection() throws SQLException{
        return DriverManager.getConnection );
    }
    
    
    
New to GrepCode? Check out our FAQ X