Skip to content

Instantly share code, notes, and snippets.

@Alcar32
Alcar32 / AbstractMethodExposingBeanExample.java
Last active December 17, 2015 09:29
AbstractMethodExposingBean Example
import de.dailab.jiactng.agentcore.action.AbstractMethodExposingBean;
public class HelloWorldExposingBean extends AbstractMethodExposingBean {
@Override
public void doInit() throws Exception {
super.doInit();
}
@Override
package examples.helloworld;
import de.dailab.jiactng.agentcore.AbstractAgentBean;
public class HelloWorldBean extends AbstractAgentBean {
@Override
public void doStart() throws Exception {
super.doStart();
log.info("Starting Hello World Bean...");
/* This sql script checks if table with name TEST_TBL exists.
* The resultset of this query is column name '1' with one row,
* if the row contains a greate than '1' then the table exists.
* If it '0' the table doesn't exist.
*
*/
select count(*) from SYS.SYSTABLES, SYS.SYSCOLUMNS
where SYS.SYSTABLES.TABLEID=SYS.SYSCOLUMNS.REFERENCEID
and SYS.SYSTABLES.TABLENAME = 'TEST_TBL';
@Alcar32
Alcar32 / CopyStringToClipboard.java
Created May 15, 2013 23:15
Copy a string to the clipboard
import java.awt.*;
import java.awt.datatransfer.*;
public static void copyStringToClipboard(String s) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(s), null);
}
@Alcar32
Alcar32 / PrintSQLException.java
Created May 15, 2013 23:16
Print SQLException Example
static void errorPrint(Throwable e) {
if (e instanceof SQLException)
SQLExceptionPrint((SQLException)e);
else
System.out.println("A non-SQL error: " + e.toString());
}
static void SQLExceptionPrint(SQLException sqle) {
while (sqle != null) {
System.out.println("\n---SQLException Caught---\n");
@Alcar32
Alcar32 / OpenConnection.java
Created May 15, 2013 23:17
Open a database connection
import java.sql.*;
Connection connection = null;
String driver = "org.apache.derby.jdbc.EmbeddedDriver";
String connectionURL = "jdbc:derby:"
connectionURL += my_db_path;
try {
// load driver
@Alcar32
Alcar32 / BackupMySQL.sh
Created May 15, 2013 23:19
How to back up and restore a MySQL database
# Back up from the command line (using mysqldump)
mysqldump --opt -u [uname] -p[pass] [dbname] > [backupfile.sql]
# Back up the MySQL database
mysqldump -u [uname] -p[pass] [dbname] | gzip -9 > [backupfile.sql.gz]
# Restoring the MySQL database
mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]
package de.dailab.joda;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Days;
import org.joda.time.Period;
import org.joda.time.format.PeriodFormatter;
@Alcar32
Alcar32 / list.sh
Created June 11, 2013 19:56
List all Java Processes with pid and complete Name of MainClass
jps -l
package example;
import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;
import java.util.Vector;
public class XmlEncodeToString {
public static void main(String[] args) throws Exception {