Tagged: java Toggle Comment Threads | Keyboard Shortcuts

  • CG 1:39 pm on February 26, 2015 Permalink | Reply
    Tags: java, queue, rabbitmq   

    Installing RabbitMQ on MacOS 

    1. Download RabbitMQ for Mac here
    2. Download Java AMQP client library here
    3. Start RabbitMQ server by running ./rabbitmq-serverBildschirmfoto 2015-02-26 um 11.10.15 vorm.
    4. Check that the server is running properly with ./rabbitmqctl statusBildschirmfoto 2015-02-26 um 11.10.51 vorm.
    5. Compile and run a HelloWorld testing program from the tutorial here. Compile the Send.java and Recv.java files with javac -cp rabbitmq-client.jar Send.java Recv.java. Run Send.java with java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Send. This will send the message (in this case the message is “Hello World!”) to the queue. And then run Recv.java with java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Recv to pop out the message on the queue.Bildschirmfoto 2015-02-26 um 11.08.05 vorm.
    6. The server and the queues can also be checked via browser http://localhost:15672/Bildschirmfoto 2015-02-26 um 11.09.31 vorm. Bildschirmfoto 2015-02-26 um 11.08.41 vorm.

    Now the queue is ready.

    Advertisements
     
    • Budi Rahardjo 8:20 am on February 28, 2015 Permalink | Reply

      On Linux (I know, it’s not Mac OS X 🙂 ) there’s “amqp-tools”. Install it with “apt-get install amqp-tools”. You’ll get five (5) command line tools. For example if you want to publish something:

      amqp-publish -e exchange_name -b “your message”

      To get a message from a queue:

      amqp-get -q queue_name
      or
      amqp-consume -q queue_name

      I believe these tools are built with rabbitmq-c library. Having said that, I looked at the newer version of rabbitmq-c library in here:
      http://alanxz.github.io/rabbitmq-c/docs/0.5.0/index.html

      It has a number of different tools. Perhaps they changed (upgraded?) the library? I have not looked deeper into it. Basically, it is a C library that you can use to create command line tools. I looked at one of the code, and hardcoded the userid dan password in it so I can use something like this.

      amqp_sendstring localhost 5672 amq.direct test “hello world”

      I have tested amqp-tools and this rabbitmq-c library agains locally installed rabbitmq server. They work!

    • Budi Rahardjo 8:37 am on February 28, 2015 Permalink | Reply

      And now for some clients. I have tested Perl Net::RabbitMQ. Getting it running is easy.

      Publishing message(s) works perfectly, but I am still having problems getting one (1) message from the queue. For some reasons, I got *all* the messages from the queue. ie. get and consume behave the same. I need to tinker some more with the get.

      I haven’t had time to play with Python and Java clients.

  • CG 7:55 pm on January 3, 2015 Permalink | Reply
    Tags: ant, canarymod, java, minecraft, mods, scriptcraft, yosemite   

    How to run Minecraft on Mac OS X Yosemite 10.10.1 

    I got this message when running Minecraft on Yosemite, and when I googled I found that this is common problems.

    Bildschirmfoto 2015-01-03 um 7.27.35 nachm.

    Some references say that the latest JDK should be installed while the earlier ones should be uninstalled. I have uninstalled the earlier and installed the latest JDK but the problem persisted.

    So I followed this reference to make it work.

    These are the steps:Install ant

    1. Download Java Application Bundler
    2. Download Minecraft.jar from here *after clicking “Show all platforms” and choose that one under “Linux and Other
    3. Create a file named build.xml and type this code in
      Bildschirmfoto 2015-01-03 um 7.22.29 nachm.
    4. Organize my file like this
      Bildschirmfoto 2015-01-03 um 7.21.13 nachm.
      *Notes: at this point, the dist folder is empty, it will contain Minecraft.app after I run ant command*
    5. Open terminal and run ant like this
      Bildschirmfoto 2015-01-03 um 7.21.56 nachm.
    6. Now the dist folder will contain Minecraft.app in it. Move it to Applications folder

    And it works!

    Bildschirmfoto 2015-01-03 um 7.17.19 nachm.

    Bildschirmfoto 2015-01-03 um 7.23.56 nachm.

    Bildschirmfoto 2015-01-03 um 7.24.02 nachm.

    My next step is to make canarymod and scriptcraft work to make mods on Minecraft. Wish me luck.

     
  • CG 7:21 pm on November 13, 2012 Permalink | Reply
    Tags: , java, java heap space   

    Resolving Java Heap Space Error 

    My previous code processed two tables with thousands of rows and had problem with Java Heap Space like shown below:

     

     

    To overcome this out of memory problem, we should increase the heap size by typing this on command prompt:

     

    And now it works:

     

    More useful links about Java heap space:

    1. http://javarevisited.blogspot.com/2011/09/javalangoutofmemoryerror-permgen-space.html
    2. http://javarevisited.blogspot.com/2011/05/java-heap-space-memory-size-jvm.html
    3. http://stackoverflow.com/questions/1565388/increase-heap-size-in-java
    4. http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html
    5. http://viralpatel.net/blogs/jvm-java-increase-heap-size-setting-heap-size-jvm-heap/
    6. http://www.devx.com/tips/Tip/5578
    7. http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fac55070_.htm
    8. http://www.ehow.com/how_5347474_set-java-heap-space.html
     
  • CG 7:17 pm on November 6, 2012 Permalink | Reply
    Tags: inserting variable into table, java, , PreparedStatement, ResultSet   

    Inserting into MySQL Table 

    Here’s how to get result from a table using ResultSet and use it as variables to be inserted to another table using PreparedStatement

    
    import java.sql.*;
    import java.sql.DriverManager;
    import java.sql.Connection;
    import com.mysql.jdbc.Driver;
    import java.net.*;
    import java.io.*;
    public class CountUser{
    public static void main(String args[]) {
    try{
    Class.forName("com.mysql.jdbc.Driver");
    // Connection connection = DriverManager.getConnection("jdbc:mysql://167.205.24.50/table","root","");
    Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/table","root","");
    Statement st1 = connection.createStatement();
    Statement st2 = connection.createStatement();
    
    ResultSet rs1 = st1.executeQuery("SELECT * FROM user");
    
    while (rs1.next()) {
    java.sql.Date date = rs1.getDate(5);
    String strDate = date.toString();
    
    PreparedStatement ps = connection.prepareStatement("INSERT INTO count_temp (no, date) VALUES (?,?)");
    ps.setInt(1, i);
    ps.setString(2, strDate);
    ps.executeUpdate();
    }
    }
    catch (Exception e){
    System.out.println("Error: " + e);
    }
    }
    }
    
     
  • CG 11:04 am on April 22, 2010 Permalink | Reply
    Tags: connection, , java, ms access, , web programming   

    How to connect Java with Microsoft Access 

    1. Install easysoft (download address: http://download.cnet.com/Easysoft-JDBC-ODBC-Bridge/3000-2065_4-10392636.html)
    2. Click ODBC Data Source Adminsitrator
    3. Choose System DSN Tab
    4. Click Add the fill in Data Source Name (ex: “test”, “my_db”)
    5. Click Select and choose the .mdb file then click OK
    6. Click Apply

    The code ( and should works ):

    import java.sql.*;
    public class Testdb
    {
    public static void main(String[] args)
    {
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:tes","","");
    Statement stmt = con.createStatement();

    //di DB saya ada tabel mhs dengan 3 field yaitu npm, nama dan alamat
    ResultSet rs = stmt.executeQuery("Select npm, nama, alamat from mhs");
    while (rs.next()) {
    int x = rs.getInt("npm");
    String s1 = rs.getString("nama");
    String s2 = rs.getString("alamat");
    System.out.println(x + " " + s1 + " " + s2 + "\n");
    }
    }
    catch (Exception e){
    System.out.println("Error: " + e);
    }

    }
    }

    Thanks to Lucky for sharing the how-to and the code.

    Useful links:

    1. http://oreilly.com/catalog/javadata/chapter/ch04.html
    2. http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2691&lngWId=2
    3. http://www.easysoft.com/applications/microsoft-access/jdbc-odbc.html
    4. http://java.sun.com/docs/books/tutorial/jdbc/overview/index.html
     
  • CG 12:45 pm on December 9, 2009 Permalink | Reply
    Tags: java,   

    Connecting java with mysql on mac os 10.5 

    1. Install MySQL downloaded from here (choose one appropriate with your mac os 10.5)
    2. Install JDBC Connecter downloaded from here. Extract the file and find “mysql-connector-java-5.1-bin.jar”. Copy the file to “library/java/extension”
    3. Compile this code to make sure that the connection works well
    import java.sql.*;
    public class connect{
       public static void main(String argv[]) throws Exception {
    
       Class.forName("com.mysql.jdbc.Driver");
    
       Connection conn = DriverManager.getConnection(
       "jdbc:mysql://localhost:3306/test",
       "root",
       "rahasia"
     );
    
     Statement stmt = conn.createStatement();
     ResultSet rset = stmt.executeQuery("SELECT now();");
    
     while (rset.next()) {
     System.out.println(rset.getString(1));
     }
    
     rset.close();
     stmt.close();
     conn.close();
     }
     }
    
    

    Notes: thanks for tutorial here.

    Useful links:

    1. http://www.wbluhm.com/MySQLTut.html
    2. http://www.pantz.org/software/mysql/mysqlcommands.html
    3. http://webdosen.bl.ac.id/dosen/050023/materi/koneksi_java_mysql.pdf
    4. http://www.kitebird.com/articles/jdbc.html
     
  • CG 12:56 am on December 8, 2009 Permalink | Reply
    Tags: java,   

    Teaching preparation 

    The phd student is distracted from finishing the Koblitz curve equation coding, and doing some mysql and connecting it to java. Will get back to the research A.S.A.P.

     
    • Budi Rahardjo 5:32 pm on December 10, 2009 Permalink | Reply

      We need the Kobliz to be done ASAP!
      Can you do it this week?
      We need progress.

      • CG 10:19 pm on December 10, 2009 Permalink | Reply

        working on it 🙂

  • CG 7:14 pm on November 6, 2008 Permalink | Reply
    Tags: java,   

    Is Java Crypto faster than C/C++? 

    One of the best IT expert and programmer I’ve ever known, suggests me to try Java for implementing crypto. He gave me lots of links and books, and now I’m going to explore more about crypto programming with Java and its library.

    Java and Eclipse have been downloaded and installed!

     
    • waskita 1:11 pm on November 12, 2008 Permalink | Reply

      ditunggu hasil implementasinya

    • CG 1:46 pm on November 12, 2008 Permalink | Reply

      @waskita: belum siap implementasi, masih mau bikin array perbandingan dulu untuk setiap library.

    • Budi Rahardjo 10:24 pm on November 12, 2008 Permalink | Reply

      Masalahnya adalah … belum ada satu library komplit yang bisa diambil modul-modulnya untuk keperluan percobaan (reconfigurable), baik dalam bahasa C/C++ maupun Java. Bisa jadi Java lebih cepat dari C (atau sebaliknya) tetapi itu belum tepat sasaran karena kayaknya tetap saja harus buat coding sendiri 🙂 [baik berupa library sendiri ataupun extend library yang sudah ada].

      Intinya: masih tetap harus kerja keras! (Hey, kata siapa grad study itu gampang. hi3.)

    • waskita 1:29 pm on November 13, 2008 Permalink | Reply

      asal jangan lama-lama, nanti jadi kayak gini: http://www.phdcomics.com/comics/archive.php?comicid=408

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel