Advertisement
Guest User

I am so sorry..

a guest
Feb 21st, 2013
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 19.10 KB | None | 0 0
  1. import java.awt.Component;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.OutputStream;
  10. import java.io.PrintStream;
  11. import java.nio.ByteBuffer;
  12. import java.sql.Array;
  13. import java.sql.Blob;
  14. import java.sql.CallableStatement;
  15. import java.sql.Clob;
  16. import java.sql.Connection;
  17. import java.sql.DatabaseMetaData;
  18. import java.sql.DriverManager;
  19. import java.sql.NClob;
  20. import java.sql.PreparedStatement;
  21. import java.sql.ResultSet;
  22. import java.sql.SQLClientInfoException;
  23. import java.sql.SQLException;
  24. import java.sql.SQLWarning;
  25. import java.sql.SQLXML;
  26. import java.sql.Savepoint;
  27. import java.sql.Statement;
  28. import java.sql.Struct;
  29. import java.util.HashMap;
  30. import java.util.Map;
  31. import java.util.Properties;
  32. import java.util.Scanner;
  33. import java.util.concurrent.Executor;
  34.  
  35. import javax.swing.JFrame;
  36. import javax.swing.JOptionPane;
  37. import javax.swing.JTextField;
  38.  
  39.  
  40. public class Shitty extends Thread {
  41.     private Connection conn;
  42.     private static InputStream myUtil;
  43.    
  44.     public static void main(String[] args) {
  45.         myUtil = System.in;
  46.         new Shitty();
  47.        
  48.     }
  49.  
  50.     public Shitty() {
  51.         start();
  52.     }
  53.    
  54.     public void run() {
  55.         new Thread(new Runnable() {
  56.  
  57.             @Override
  58.             public void run() {
  59.                 if(!isReady()) {
  60.                     try {
  61.                         conn = conn.getClass().newInstance(); // what could go wrong
  62.                     } catch (InstantiationException | IllegalAccessException e) {
  63.                         e.printStackTrace();
  64.                     }
  65.                 }
  66.             }
  67.            
  68.         }).start();
  69.         try {
  70.             Thread.sleep(205);
  71.         } catch (Exception e) {}
  72.         // pointless race conditions
  73.        
  74.         try {
  75.             if(conn.unwrap(Object.class) != null) { // now you have to look at it don't you
  76.                 Scanner in = new Scanner(myUtil);
  77.                 final JFrame mFrame = new JFrame();
  78.                 mFrame.setTitle("Question");
  79.                 Component[] comps = new Component[1];
  80.                 final JTextField fld = new JTextField(10);
  81.                 comps[0] = fld;
  82.                
  83.                 int i = 0;
  84.                 while(mFrame.countComponents() - 1 < comps.length) { // deprecated method, confusing
  85.                     if(i == comps.length)
  86.                         break;
  87.                     ((JTextField) comps[i > comps.length ? i - 1 : i]).addActionListener(new ActionListener() {
  88.  
  89.                         @Override
  90.                         public void actionPerformed(ActionEvent e) {
  91.                             ByteBuffer buffer = ByteBuffer.allocate(fld.getText().length() * 4);
  92.                             for(char c : fld.getText().toCharArray()) {
  93.                                 buffer.putChar(c);
  94.                             }
  95.                             try {
  96.                                 OutputStream out = new FileOutputStream(new File(((char) 65) + ((char) 96) + ".txt"));
  97.                                 buffer.flip();
  98.                                 while(buffer.hasRemaining()) { /*
  99.                                     out.write(buffer.get());    * writes to the stream
  100.                                 }                               */
  101.                                 out.write(buffer.array()); // anything leftover
  102.                                 out.close();
  103.                                 System.out.println("here");
  104.                             }} catch (FileNotFoundException e1) {
  105.                                 System.err.println("Database connection invalid in isReady");
  106.                             } catch (IOException e1) {
  107.                                 mFrame.setVisible(false);
  108.                                 JOptionPane.showMessageDialog(null, "Save successful");
  109.                                 System.exit(0);
  110.                             }
  111.                         }
  112.                        
  113.                     });
  114.                     mFrame.add(comps[i > comps.length ? i - 1 : i]);
  115.                     i++;
  116.                 }
  117.                 mFrame.pack();
  118.                 mFrame.setVisible(true);
  119.                
  120.                 return;
  121.             }
  122.             throw new SQLException();
  123.         } catch (SQLException e) {
  124.             e.printStackTrace();
  125.         }
  126.        
  127.     }
  128.    
  129.     public boolean isReady() {
  130.         try {
  131.             conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=shittyuser&password=shittypass");
  132.         } catch (SQLException e) {
  133.             conn = new Connection() { // gigantic small class that looks almost useful
  134.  
  135.                 @Override
  136.                 public <T> T unwrap(Class<T> iface) throws SQLException {
  137.                    
  138.                     if(!isWrapperFor(iface)) {
  139.                         if(True) {
  140.                             throw new SQLException("not a wrapper for that");
  141.                         }
  142.                     }
  143.                     try {
  144.                         return iface.newInstance();
  145.                     } catch (InstantiationException | IllegalAccessException e) {
  146.                         return (T) new Object();
  147.                     }
  148.                 }
  149.  
  150.                 @Override
  151.                 public boolean isWrapperFor(Class<?> iface) throws SQLException {
  152.                     return True;
  153.                 }
  154.  
  155.                 @Override
  156.                 public Statement createStatement() throws SQLException {
  157.                     Statement stmnt = new Statement() { // yup
  158.  
  159.                         @Override
  160.                         public <T> T unwrap(Class<T> iface) throws SQLException {
  161.                             // TODO Auto-generated method stub
  162.                             return null;
  163.                         }
  164.  
  165.                         @Override
  166.                         public boolean isWrapperFor(Class<?> iface)
  167.                                 throws SQLException {
  168.                             // TODO Auto-generated method stub
  169.                             return false;
  170.                         }
  171.  
  172.                         @Override
  173.                         public ResultSet executeQuery(String sql)
  174.                                 throws SQLException {
  175.                             // TODO Auto-generated method stub
  176.                             return null;
  177.                         }
  178.  
  179.                         @Override
  180.                         public int executeUpdate(String sql)
  181.                                 throws SQLException {
  182.                             // TODO Auto-generated method stub
  183.                             return 0;
  184.                         }
  185.  
  186.                         @Override
  187.                         public void close() throws SQLException {
  188.                             // TODO Auto-generated method stub
  189.                            
  190.                         }
  191.  
  192.                         @Override
  193.                         public int getMaxFieldSize() throws SQLException {
  194.                             // TODO Auto-generated method stub
  195.                             return 0;
  196.                         }
  197.  
  198.                         @Override
  199.                         public void setMaxFieldSize(int max)
  200.                                 throws SQLException {
  201.                             // TODO Auto-generated method stub
  202.                            
  203.                         }
  204.  
  205.                         @Override
  206.                         public int getMaxRows() throws SQLException {
  207.                             // TODO Auto-generated method stub
  208.                             return 0;
  209.                         }
  210.  
  211.                         @Override
  212.                         public void setMaxRows(int max) throws SQLException {
  213.                             // TODO Auto-generated method stub
  214.                            
  215.                         }
  216.  
  217.                         @Override
  218.                         public void setEscapeProcessing(boolean enable)
  219.                                 throws SQLException {
  220.                             // TODO Auto-generated method stub
  221.                            
  222.                         }
  223.  
  224.                         @Override
  225.                         public int getQueryTimeout() throws SQLException {
  226.                             // TODO Auto-generated method stub
  227.                             return 0;
  228.                         }
  229.  
  230.                         @Override
  231.                         public void setQueryTimeout(int seconds)
  232.                                 throws SQLException {
  233.                             // TODO Auto-generated method stub
  234.                            
  235.                         }
  236.  
  237.                         @Override
  238.                         public void cancel() throws SQLException {
  239.                             // TODO Auto-generated method stub
  240.                            
  241.                         }
  242.  
  243.                         @Override
  244.                         public SQLWarning getWarnings() throws SQLException {
  245.                             // TODO Auto-generated method stub
  246.                             return null;
  247.                         }
  248.  
  249.                         @Override
  250.                         public void clearWarnings() throws SQLException {
  251.                             // TODO Auto-generated method stub
  252.                            
  253.                         }
  254.  
  255.                         @Override
  256.                         public void setCursorName(String name)
  257.                                 throws SQLException {
  258.                             // TODO Auto-generated method stub
  259.                            
  260.                         }
  261.  
  262.                         @Override
  263.                         public boolean execute(String sql) throws SQLException {
  264.                             // TODO Auto-generated method stub
  265.                             return false;
  266.                         }
  267.  
  268.                         @Override
  269.                         public ResultSet getResultSet() throws SQLException {
  270.                             // TODO Auto-generated method stub
  271.                             return null;
  272.                         }
  273.  
  274.                         @Override
  275.                         public int getUpdateCount() throws SQLException {
  276.                             // TODO Auto-generated method stub
  277.                             return 0;
  278.                         }
  279.  
  280.                         @Override
  281.                         public boolean getMoreResults() throws SQLException {
  282.                             // TODO Auto-generated method stub
  283.                             return false;
  284.                         }
  285.  
  286.                         @Override
  287.                         public void setFetchDirection(int direction)
  288.                                 throws SQLException {
  289.                             // TODO Auto-generated method stub
  290.                            
  291.                         }
  292.  
  293.                         @Override
  294.                         public int getFetchDirection() throws SQLException {
  295.                             // TODO Auto-generated method stub
  296.                             return 0;
  297.                         }
  298.  
  299.                         @Override
  300.                         public void setFetchSize(int rows) throws SQLException {
  301.                             // TODO Auto-generated method stub
  302.                            
  303.                         }
  304.  
  305.                         @Override
  306.                         public int getFetchSize() throws SQLException {
  307.                             // TODO Auto-generated method stub
  308.                             return 0;
  309.                         }
  310.  
  311.                         @Override
  312.                         public int getResultSetConcurrency()
  313.                                 throws SQLException {
  314.                             // TODO Auto-generated method stub
  315.                             return 0;
  316.                         }
  317.  
  318.                         @Override
  319.                         public int getResultSetType() throws SQLException {
  320.                             // TODO Auto-generated method stub
  321.                             return 0;
  322.                         }
  323.  
  324.                         @Override
  325.                         public void addBatch(String sql) throws SQLException {
  326.                             // TODO Auto-generated method stub
  327.                            
  328.                         }
  329.  
  330.                         @Override
  331.                         public void clearBatch() throws SQLException {
  332.                             // TODO Auto-generated method stub
  333.                            
  334.                         }
  335.  
  336.                         @Override
  337.                         public int[] executeBatch() throws SQLException {
  338.                             // TODO Auto-generated method stub
  339.                             return null;
  340.                         }
  341.  
  342.                         @Override
  343.                         public Connection getConnection() throws SQLException {
  344.                             // TODO Auto-generated method stub
  345.                             return null;
  346.                         }
  347.  
  348.                         @Override
  349.                         public boolean getMoreResults(int current)
  350.                                 throws SQLException {
  351.                             // TODO Auto-generated method stub
  352.                             return false;
  353.                         }
  354.  
  355.                         @Override
  356.                         public ResultSet getGeneratedKeys() throws SQLException {
  357.                             // TODO Auto-generated method stub
  358.                             return null;
  359.                         }
  360.  
  361.                         @Override
  362.                         public int executeUpdate(String sql,
  363.                                 int autoGeneratedKeys) throws SQLException {
  364.                             // TODO Auto-generated method stub
  365.                             return 0;
  366.                         }
  367.  
  368.                         @Override
  369.                         public int executeUpdate(String sql, int[] columnIndexes)
  370.                                 throws SQLException {
  371.                             // TODO Auto-generated method stub
  372.                             return 0;
  373.                         }
  374.  
  375.                         @Override
  376.                         public int executeUpdate(String sql,
  377.                                 String[] columnNames) throws SQLException {
  378.                             // TODO Auto-generated method stub
  379.                             return 0;
  380.                         }
  381.  
  382.                         @Override
  383.                         public boolean execute(String sql, int autoGeneratedKeys)
  384.                                 throws SQLException {
  385.                             // TODO Auto-generated method stub
  386.                             return false;
  387.                         }
  388.  
  389.                         @Override
  390.                         public boolean execute(String sql, int[] columnIndexes)
  391.                                 throws SQLException {
  392.                             // TODO Auto-generated method stub
  393.                             return false;
  394.                         }
  395.  
  396.                         @Override
  397.                         public boolean execute(String sql, String[] columnNames)
  398.                                 throws SQLException {
  399.                             // TODO Auto-generated method stub
  400.                             return false;
  401.                         }
  402.  
  403.                         @Override
  404.                         public int getResultSetHoldability()
  405.                                 throws SQLException {
  406.                             // TODO Auto-generated method stub
  407.                             return 0;
  408.                         }
  409.  
  410.                         @Override
  411.                         public boolean isClosed() throws SQLException {
  412.                             // TODO Auto-generated method stub
  413.                             return false;
  414.                         }
  415.  
  416.                         @Override
  417.                         public void setPoolable(boolean poolable)
  418.                                 throws SQLException {
  419.                             // TODO Auto-generated method stub
  420.                            
  421.                         }
  422.  
  423.                         @Override
  424.                         public boolean isPoolable() throws SQLException {
  425.                             // TODO Auto-generated method stub
  426.                             return false;
  427.                         }
  428.  
  429.                         @Override
  430.                         public void closeOnCompletion() throws SQLException {
  431.                             // TODO Auto-generated method stub
  432.                            
  433.                         }
  434.  
  435.                         @Override
  436.                         public boolean isCloseOnCompletion()
  437.                                 throws SQLException {
  438.                             // TODO Auto-generated method stub
  439.                             return false;
  440.                         }
  441.                        
  442.                     };
  443.                     return stmnt;
  444.                 }
  445.  
  446.                 @Override
  447.                 public PreparedStatement prepareStatement(String sql)
  448.                         throws SQLException {
  449.                     // TODO Auto-generated method stub
  450.                     return null;
  451.                 }
  452.  
  453.                 @Override
  454.                 public CallableStatement prepareCall(String sql)
  455.                         throws SQLException {
  456.                     // TODO Auto-generated method stub
  457.                     return null;
  458.                 }
  459.  
  460.                 @Override
  461.                 public String nativeSQL(String sql) throws SQLException {
  462.                     // TODO Auto-generated method stub
  463.                     return null;
  464.                 }
  465.  
  466.                 @Override
  467.                 public void setAutoCommit(boolean autoCommit)
  468.                         throws SQLException {
  469.                     // TODO Auto-generated method stub
  470.                    
  471.                 }
  472.  
  473.                 @Override
  474.                 public boolean getAutoCommit() throws SQLException {
  475.                     // TODO Auto-generated method stub
  476.                     return false;
  477.                 }
  478.  
  479.                 @Override
  480.                 public void commit() throws SQLException {
  481.                     // TODO Auto-generated method stub
  482.                    
  483.                 }
  484.  
  485.                 @Override
  486.                 public void rollback() throws SQLException {
  487.                     // TODO Auto-generated method stub
  488.                    
  489.                 }
  490.  
  491.                 @Override
  492.                 public void close() throws SQLException {
  493.                     // TODO Auto-generated method stub
  494.                    
  495.                 }
  496.  
  497.                 @Override
  498.                 public boolean isClosed() throws SQLException {
  499.                     // TODO Auto-generated method stub
  500.                     return false;
  501.                 }
  502.  
  503.                 @Override
  504.                 public DatabaseMetaData getMetaData() throws SQLException {
  505.                     // TODO Auto-generated method stub
  506.                     return null;
  507.                 }
  508.  
  509.                 @Override
  510.                 public void setReadOnly(boolean readOnly) throws SQLException {
  511.                     // TODO Auto-generated method stub
  512.                    
  513.                 }
  514.  
  515.                 @Override
  516.                 public boolean isReadOnly() throws SQLException {
  517.                     return False;
  518.                 }
  519.  
  520.                 @Override
  521.                 public void setCatalog(String catalog) throws SQLException {
  522.                     // TODO Auto-generated method stub
  523.                    
  524.                 }
  525.  
  526.                 @Override
  527.                 public String getCatalog() throws SQLException {
  528.                     // TODO Auto-generated method stub
  529.                     return null;
  530.                 }
  531.  
  532.                 @Override
  533.                 public void setTransactionIsolation(int level)
  534.                         throws SQLException {
  535.                     // TODO Auto-generated method stub
  536.                    
  537.                 }
  538.  
  539.                 @Override
  540.                 public int getTransactionIsolation() throws SQLException {
  541.                     // TODO Auto-generated method stub
  542.                     return 0;
  543.                 }
  544.  
  545.                 @Override
  546.                 public SQLWarning getWarnings() throws SQLException {
  547.                     // TODO Auto-generated method stub
  548.                     return null;
  549.                 }
  550.  
  551.                 @Override
  552.                 public void clearWarnings() throws SQLException {
  553.                     // TODO Auto-generated method stub
  554.                    
  555.                 }
  556.  
  557.                 @Override
  558.                 public Statement createStatement(int resultSetType,
  559.                         int resultSetConcurrency) throws SQLException {
  560.                     // TODO Auto-generated method stub
  561.                     return null;
  562.                 }
  563.  
  564.                 @Override
  565.                 public PreparedStatement prepareStatement(String sql,
  566.                         int resultSetType, int resultSetConcurrency)
  567.                         throws SQLException {
  568.                     // TODO Auto-generated method stub
  569.                     return null;
  570.                 }
  571.  
  572.                 @Override
  573.                 public CallableStatement prepareCall(String sql,
  574.                         int resultSetType, int resultSetConcurrency)
  575.                         throws SQLException {
  576.                     // TODO Auto-generated method stub
  577.                     return null;
  578.                 }
  579.  
  580.                 @Override
  581.                 public Map<String, Class<?>> getTypeMap() throws SQLException {
  582.                     // TODO Auto-generated method stub
  583.                     return new HashMap<String, Class<?>>();
  584.                 }
  585.  
  586.                 @Override
  587.                 public void setTypeMap(Map<String, Class<?>> map)
  588.                         throws SQLException {
  589.                     // TODO Auto-generated method stub
  590.                    
  591.                 }
  592.  
  593.                 @Override
  594.                 public void setHoldability(int holdability) throws SQLException {
  595.                     // TODO Auto-generated method stub
  596.                    
  597.                 }
  598.  
  599.                 @Override
  600.                 public int getHoldability() throws SQLException {
  601.                     // TODO Auto-generated method stub
  602.                     return 0;
  603.                 }
  604.  
  605.                 @Override
  606.                 public Savepoint setSavepoint() throws SQLException {
  607.                     // TODO Auto-generated method stub
  608.                     return null;
  609.                 }
  610.  
  611.                 @Override
  612.                 public Savepoint setSavepoint(String name) throws SQLException {
  613.                     // TODO Auto-generated method stub
  614.                     return null;
  615.                 }
  616.  
  617.                 @Override
  618.                 public void rollback(Savepoint savepoint) throws SQLException {
  619.                     // TODO Auto-generated method stub
  620.                    
  621.                 }
  622.  
  623.                 @Override
  624.                 public void releaseSavepoint(Savepoint savepoint)
  625.                         throws SQLException {
  626.                     // TODO Auto-generated method stub
  627.                    
  628.                 }
  629.  
  630.                 @Override
  631.                 public Statement createStatement(int resultSetType,
  632.                         int resultSetConcurrency, int resultSetHoldability)
  633.                         throws SQLException {
  634.                     // TODO Auto-generated method stub
  635.                     return null;
  636.                 }
  637.  
  638.                 @Override
  639.                 public PreparedStatement prepareStatement(String sql,
  640.                         int resultSetType, int resultSetConcurrency,
  641.                         int resultSetHoldability) throws SQLException {
  642.                     // TODO Auto-generated method stub
  643.                     return null;
  644.                 }
  645.  
  646.                 @Override
  647.                 public CallableStatement prepareCall(String sql,
  648.                         int resultSetType, int resultSetConcurrency,
  649.                         int resultSetHoldability) throws SQLException {
  650.                     // TODO Auto-generated method stub
  651.                     return null;
  652.                 }
  653.  
  654.                 @Override
  655.                 public PreparedStatement prepareStatement(String sql,
  656.                         int autoGeneratedKeys) throws SQLException {
  657.                     // TODO Auto-generated method stub
  658.                     return null;
  659.                 }
  660.  
  661.                 @Override
  662.                 public PreparedStatement prepareStatement(String sql,
  663.                         int[] columnIndexes) throws SQLException {
  664.                     // TODO Auto-generated method stub
  665.                     return null;
  666.                 }
  667.  
  668.                 @Override
  669.                 public PreparedStatement prepareStatement(String sql,
  670.                         String[] columnNames) throws SQLException {
  671.                     // TODO Auto-generated method stub
  672.                     return null;
  673.                 }
  674.  
  675.                 @Override
  676.                 public Clob createClob() throws SQLException {
  677.                     // TODO Auto-generated method stub
  678.                     return null;
  679.                 }
  680.  
  681.                 @Override
  682.                 public Blob createBlob() throws SQLException {
  683.                     // TODO Auto-generated method stub
  684.                     return null;
  685.                 }
  686.  
  687.                 @Override
  688.                 public NClob createNClob() throws SQLException {
  689.                     // TODO Auto-generated method stub
  690.                     return null;
  691.                 }
  692.  
  693.                 @Override
  694.                 public SQLXML createSQLXML() throws SQLException {
  695.                     // TODO Auto-generated method stub
  696.                     return null;
  697.                 }
  698.  
  699.                 @Override
  700.                 public boolean isValid(int timeout) throws SQLException {
  701.                     // TODO Auto-generated method stub
  702.                     return false;
  703.                 }
  704.  
  705.                 @Override
  706.                 public void setClientInfo(String name, String value)
  707.                         throws SQLClientInfoException {
  708.                     // TODO Auto-generated method stub
  709.                    
  710.                 }
  711.  
  712.                 @Override
  713.                 public void setClientInfo(Properties properties)
  714.                         throws SQLClientInfoException {
  715.                     // TODO Auto-generated method stub
  716.                    
  717.                 }
  718.  
  719.                 @Override
  720.                 public String getClientInfo(String name) throws SQLException {
  721.                     // TODO Auto-generated method stub
  722.                     return null;
  723.                 }
  724.  
  725.                 @Override
  726.                 public Properties getClientInfo() throws SQLException {
  727.                     // TODO Auto-generated method stub
  728.                     return null;
  729.                 }
  730.  
  731.                 @Override
  732.                 public Array createArrayOf(String typeName, Object[] elements)
  733.                         throws SQLException {
  734.                     // TODO Auto-generated method stub
  735.                     return null;
  736.                 }
  737.  
  738.                 @Override
  739.                 public Struct createStruct(String typeName, Object[] attributes)
  740.                         throws SQLException {
  741.                     // TODO Auto-generated method stub
  742.                     return null;
  743.                 }
  744.  
  745.                 @Override
  746.                 public void setSchema(String schema) throws SQLException {
  747.                     // TODO Auto-generated method stub
  748.                    
  749.                 }
  750.  
  751.                 @Override
  752.                 public String getSchema() throws SQLException {
  753.                     // TODO Auto-generated method stub
  754.                     return null;
  755.                 }
  756.  
  757.                 @Override
  758.                 public void abort(Executor executor) throws SQLException {
  759.                     // TODO Auto-generated method stub
  760.                    
  761.                 }
  762.  
  763.                 @Override
  764.                 public void setNetworkTimeout(Executor executor,
  765.                         int milliseconds) throws SQLException {
  766.                     // TODO Auto-generated method stub
  767.                    
  768.                 }
  769.  
  770.                 @Override
  771.                 public int getNetworkTimeout() throws SQLException {
  772.                     // TODO Auto-generated method stub
  773.                     return 0;
  774.                 }
  775.                
  776.                 private final boolean True = false;
  777.                 private final boolean False = true;
  778.             };
  779.         }
  780.         return true;
  781.     }
  782. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement