خرید بک لینک

Vote count: 0

This is related to Not able to retrieve the column names correctly with memcached.

I have a scala code to cache the MYSQL data using memcached. Below is the code.

import java.sql.DriverManager
import scala.collection.mutable.ArrayBuffer
import java.sql.ResultSet
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import net.spy.memcached.MemcachedClient
import net.spy.memcached.AddrUtil
import net.spy.memcached.BinaryCoectionFactory
import com.sun.rowset.CachedRowSetImpl
import java.util.concurrent.TimeoutException
import java.util.concurrent.TimeUnit

object Memcachedtest 
{
  def MD5encode(query_line:String):String=
    {
        var md5:String=null;

        if (query_line == null) retu null;

        try {
            val digest1:MessageDigest = MessageDigest.getInstance("MD5");
             val hash:Array[Byte]  =digest1.digest(query_line.getBytes());
            val sb:StringBuilder = new StringBuilder(2*hash.length);

            digest1.update(query_line.getBytes());
            for(b <- hash)
            {
                sb.append("%02x".format( b&0xff));
            }
            md5=sb.toString();
        }
        catch 
        {
        case e:NoSuchAlgorithmException => e.printStackTrace();
        }
         md5
    }

  def memcache_get_result(mysql_table_statement:String)
  {
    var crsi:CachedRowSetImpl=new CachedRowSetImpl();
    var mem_client:MemcachedClient=new MemcachedClient(new BinaryCoectionFactory(), AddrUtil.getAddresses("IP"))

         var obj:Object=null
         Class.forName("com.mysql.jdbc.Driver");

            val co =  DriverManager.getCoection("jdbc:mysql:IP","user","pass");
        val query_md5_res=MD5encode(mysql_table_statement);
             var future_object=mem_client.asyncGet(query_md5_res);
            try {
                obj=future_object.get(5, TimeUnit.SECONDS);
            }
            catch {

              case t:TimeoutException =>    future_object.cancel(false);
                System.out.println("Memcached timeout...");
            }
            if (obj==null) {
                System.out.print("Query result not in Memcached, ");
                var res:ResultSet = co.createStatement().executeQuery(mysql_table_statement);
                crsi.populate(res);

                res.close();
                mem_client.set(query_md5_res, 10, crsi);
                while (crsi.next()) {

                  System.out.print("output : " + crsi.getString("COLUMN_ID"));
                }
                crsi.close();
            }
            else  {
                System.out.print("Query result in Memcached, ");
                var crsi_res_set:CachedRowSetImpl=obj.asInstanceOf[CachedRowSetImpl]
                System.out.println(crsi_res_set);
                crsi_res_set.beforeFirst();
                while (crsi_res_set.next()) {

                    System.out.print("output : " + crsi.getString("COLUMN_ID"));
                }
                crsi_res_set.close();
            }

        if (co != null) {
            co.close();
        }
  }

   def main(args:Array[String])
    {
      var crsi:CachedRowSetImpl=new CachedRowSetImpl();
      var mem_client:MemcachedClient=new MemcachedClient(new BinaryCoectionFactory(), AddrUtil.getAddresses("IP"))
      memcache_get_result("select statement")
      memcache_get_result("select statement")

        mem_client.shutdown();
    }


}

The problem with this approach, to retrieve the MYSQL data when i use the new MYSQL coector(after 5.0.4) the column names are not retrieved properly. If i have columns like A_ID,B_ID,C_ID when it passes through crsi.next and when i try to get the value with crsi.getString(Columame) i did not get any values, later i found out that all the three columns just had a single column name ID, prefix is ignored, so when i try to get the value with crsi.getString(ID) i am able to get the value but not with crsi.getString(A_ID). All the three column names are stored with ID.

But with mysql coector version 5.0.4 it is working properly. But why it is not working with any newer versions. Any workaround for this, because using the lower end coector version does affect other parts of the code.

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 15 ارديبهشت 1395 ساعت: 11:21

صفحه بندی