Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Component;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.PrintStream;
- import java.nio.ByteBuffer;
- import java.sql.Array;
- import java.sql.Blob;
- import java.sql.CallableStatement;
- import java.sql.Clob;
- import java.sql.Connection;
- import java.sql.DatabaseMetaData;
- import java.sql.DriverManager;
- import java.sql.NClob;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLClientInfoException;
- import java.sql.SQLException;
- import java.sql.SQLWarning;
- import java.sql.SQLXML;
- import java.sql.Savepoint;
- import java.sql.Statement;
- import java.sql.Struct;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Properties;
- import java.util.Scanner;
- import java.util.concurrent.Executor;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- public class Shitty extends Thread {
- private Connection conn;
- private static InputStream myUtil;
- public static void main(String[] args) {
- myUtil = System.in;
- new Shitty();
- }
- public Shitty() {
- start();
- }
- public void run() {
- new Thread(new Runnable() {
- @Override
- public void run() {
- if(!isReady()) {
- try {
- conn = conn.getClass().newInstance(); // what could go wrong
- } catch (InstantiationException | IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- }
- }).start();
- try {
- Thread.sleep(205);
- } catch (Exception e) {}
- // pointless race conditions
- try {
- if(conn.unwrap(Object.class) != null) { // now you have to look at it don't you
- Scanner in = new Scanner(myUtil);
- final JFrame mFrame = new JFrame();
- mFrame.setTitle("Question");
- Component[] comps = new Component[1];
- final JTextField fld = new JTextField(10);
- comps[0] = fld;
- int i = 0;
- while(mFrame.countComponents() - 1 < comps.length) { // deprecated method, confusing
- if(i == comps.length)
- break;
- ((JTextField) comps[i > comps.length ? i - 1 : i]).addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- ByteBuffer buffer = ByteBuffer.allocate(fld.getText().length() * 4);
- for(char c : fld.getText().toCharArray()) {
- buffer.putChar(c);
- }
- try {
- OutputStream out = new FileOutputStream(new File(((char) 65) + ((char) 96) + ".txt"));
- buffer.flip();
- while(buffer.hasRemaining()) { /*
- out.write(buffer.get()); * writes to the stream
- } */
- out.write(buffer.array()); // anything leftover
- out.close();
- System.out.println("here");
- }} catch (FileNotFoundException e1) {
- System.err.println("Database connection invalid in isReady");
- } catch (IOException e1) {
- mFrame.setVisible(false);
- JOptionPane.showMessageDialog(null, "Save successful");
- System.exit(0);
- }
- }
- });
- mFrame.add(comps[i > comps.length ? i - 1 : i]);
- i++;
- }
- mFrame.pack();
- mFrame.setVisible(true);
- return;
- }
- throw new SQLException();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public boolean isReady() {
- try {
- conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=shittyuser&password=shittypass");
- } catch (SQLException e) {
- conn = new Connection() { // gigantic small class that looks almost useful
- @Override
- public <T> T unwrap(Class<T> iface) throws SQLException {
- if(!isWrapperFor(iface)) {
- if(True) {
- throw new SQLException("not a wrapper for that");
- }
- }
- try {
- return iface.newInstance();
- } catch (InstantiationException | IllegalAccessException e) {
- return (T) new Object();
- }
- }
- @Override
- public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return True;
- }
- @Override
- public Statement createStatement() throws SQLException {
- Statement stmnt = new Statement() { // yup
- @Override
- public <T> T unwrap(Class<T> iface) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public boolean isWrapperFor(Class<?> iface)
- throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public ResultSet executeQuery(String sql)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public int executeUpdate(String sql)
- throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public void close() throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public int getMaxFieldSize() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public void setMaxFieldSize(int max)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public int getMaxRows() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public void setMaxRows(int max) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public void setEscapeProcessing(boolean enable)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public int getQueryTimeout() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public void setQueryTimeout(int seconds)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public void cancel() throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public SQLWarning getWarnings() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void clearWarnings() throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public void setCursorName(String name)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public boolean execute(String sql) throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public ResultSet getResultSet() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public int getUpdateCount() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public boolean getMoreResults() throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public void setFetchDirection(int direction)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public int getFetchDirection() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public void setFetchSize(int rows) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public int getFetchSize() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public int getResultSetConcurrency()
- throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public int getResultSetType() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public void addBatch(String sql) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public void clearBatch() throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public int[] executeBatch() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public Connection getConnection() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public boolean getMoreResults(int current)
- throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public ResultSet getGeneratedKeys() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public int executeUpdate(String sql,
- int autoGeneratedKeys) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public int executeUpdate(String sql, int[] columnIndexes)
- throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public int executeUpdate(String sql,
- String[] columnNames) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public boolean execute(String sql, int autoGeneratedKeys)
- throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public boolean execute(String sql, int[] columnIndexes)
- throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public boolean execute(String sql, String[] columnNames)
- throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public int getResultSetHoldability()
- throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public boolean isClosed() throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public void setPoolable(boolean poolable)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public boolean isPoolable() throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public void closeOnCompletion() throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public boolean isCloseOnCompletion()
- throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- };
- return stmnt;
- }
- @Override
- public PreparedStatement prepareStatement(String sql)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public CallableStatement prepareCall(String sql)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public String nativeSQL(String sql) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void setAutoCommit(boolean autoCommit)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public boolean getAutoCommit() throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public void commit() throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public void rollback() throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public void close() throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public boolean isClosed() throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public DatabaseMetaData getMetaData() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void setReadOnly(boolean readOnly) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public boolean isReadOnly() throws SQLException {
- return False;
- }
- @Override
- public void setCatalog(String catalog) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public String getCatalog() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void setTransactionIsolation(int level)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public int getTransactionIsolation() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public SQLWarning getWarnings() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void clearWarnings() throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public Statement createStatement(int resultSetType,
- int resultSetConcurrency) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public PreparedStatement prepareStatement(String sql,
- int resultSetType, int resultSetConcurrency)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public CallableStatement prepareCall(String sql,
- int resultSetType, int resultSetConcurrency)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public Map<String, Class<?>> getTypeMap() throws SQLException {
- // TODO Auto-generated method stub
- return new HashMap<String, Class<?>>();
- }
- @Override
- public void setTypeMap(Map<String, Class<?>> map)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public void setHoldability(int holdability) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public int getHoldability() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public Savepoint setSavepoint() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public Savepoint setSavepoint(String name) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void rollback(Savepoint savepoint) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public void releaseSavepoint(Savepoint savepoint)
- throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public Statement createStatement(int resultSetType,
- int resultSetConcurrency, int resultSetHoldability)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public PreparedStatement prepareStatement(String sql,
- int resultSetType, int resultSetConcurrency,
- int resultSetHoldability) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public CallableStatement prepareCall(String sql,
- int resultSetType, int resultSetConcurrency,
- int resultSetHoldability) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public PreparedStatement prepareStatement(String sql,
- int autoGeneratedKeys) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public PreparedStatement prepareStatement(String sql,
- int[] columnIndexes) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public PreparedStatement prepareStatement(String sql,
- String[] columnNames) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public Clob createClob() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public Blob createBlob() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public NClob createNClob() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public SQLXML createSQLXML() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public boolean isValid(int timeout) throws SQLException {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public void setClientInfo(String name, String value)
- throws SQLClientInfoException {
- // TODO Auto-generated method stub
- }
- @Override
- public void setClientInfo(Properties properties)
- throws SQLClientInfoException {
- // TODO Auto-generated method stub
- }
- @Override
- public String getClientInfo(String name) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public Properties getClientInfo() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public Array createArrayOf(String typeName, Object[] elements)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public Struct createStruct(String typeName, Object[] attributes)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void setSchema(String schema) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public String getSchema() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void abort(Executor executor) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public void setNetworkTimeout(Executor executor,
- int milliseconds) throws SQLException {
- // TODO Auto-generated method stub
- }
- @Override
- public int getNetworkTimeout() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
- private final boolean True = false;
- private final boolean False = true;
- };
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement