<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-2061895051345547701</atom:id><lastBuildDate>Tue, 24 Sep 2024 12:16:27 +0000</lastBuildDate><category>Connection</category><category>MySQL</category><category>SQLServer</category><category>Adding</category><category>C#</category><category>CSharp</category><category>JDBC</category><category>Java</category><category>Leading</category><category>Library</category><category>Oracle</category><category>Replicate</category><category>Zeros</category><title>Prograstinate: Pick up your Towels</title><description></description><link>http://prograstinate.blogspot.com/</link><managingEditor>noreply@blogger.com (Nataniel)</managingEditor><generator>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2061895051345547701.post-6763859888242438111</guid><pubDate>Fri, 12 Jul 2013 16:23:00 +0000</pubDate><atom:updated>2014-04-24T06:52:55.869-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Adding</category><category domain="http://www.blogger.com/atom/ns#">Leading</category><category domain="http://www.blogger.com/atom/ns#">Replicate</category><category domain="http://www.blogger.com/atom/ns#">SQLServer</category><category domain="http://www.blogger.com/atom/ns#">Zeros</category><title>SQL Server - Adding Leading Zeros</title><description>Well, sometimes you need to do some query in a numeric field and you need to add leading zeros for formatation purpose.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
It&#39;s prety easy to do this! Take a look in the following query:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
You&#39;ll use &#39;REPLICATE&#39; to do the work here!&lt;br /&gt;
&lt;pre style=&quot;font-family: Consolas, Courier, monospace; font-size: 13px; line-height: 17px; overflow: auto; padding: 5px; word-wrap: normal;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Consolas, Courier, monospace; font-size: 13px; line-height: 17px; overflow: auto; padding: 5px; word-wrap: normal;&quot;&gt;REPLICATE (&amp;nbsp;string_expression ,integer_expression ) &lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
Where string_expression is the string you want to replicate and integer_expression is the amount of times o want to replicate string_expression.&lt;br /&gt;
&lt;br /&gt;
In my example:&lt;br /&gt;
string_expression: &#39;0&#39;. Wich means I want to replicate &#39;0&#39;.&lt;br /&gt;
integer_expression: 4 - LEN(CAST(id_user as varchar))). &amp;nbsp;I subtract id_user&#39;s length from the amount of times that I want to replicate &#39;0&#39;.&lt;br /&gt;
&lt;br /&gt;
And in the end I concatenate the result of REPLICATE function with the field I did all the work.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/natanfrost/76525a066701c486457b.js&quot;&gt;&lt;/script&gt;

&lt;div&gt;
&lt;br /&gt;
This is the example without REPLICATE:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://dl.dropboxusercontent.com/u/23214803/Blog/imgs/replicate_1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://dl.dropboxusercontent.com/u/23214803/Blog/imgs/replicate_1.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
This will be the result with REPLICATE:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://dl.dropboxusercontent.com/u/23214803/Blog/imgs/replicate_2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://dl.dropboxusercontent.com/u/23214803/Blog/imgs/replicate_2.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</description><link>http://prograstinate.blogspot.com/2013/07/sql-server-adding-leading-zeros.html</link><author>noreply@blogger.com (Nataniel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2061895051345547701.post-2282069140671371601</guid><pubDate>Fri, 12 Jul 2013 12:27:00 +0000</pubDate><atom:updated>2014-04-24T06:53:54.911-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Connection</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><category domain="http://www.blogger.com/atom/ns#">MySQL</category><category domain="http://www.blogger.com/atom/ns#">Oracle</category><category domain="http://www.blogger.com/atom/ns#">SQLServer</category><title>Connection Class C# (SQLServer, Oracle, MySQL)</title><description>What&#39;s up? Yeah, I&#39;m a little lazy I know. It&#39;s been almost 2 years since I don&#39;t create new content to post in here. The time passed and now I don&#39;t really like Java that much :p&lt;br /&gt;
&lt;br /&gt;
Now, I will show a example of connection in C# + SQLServer, C# + MySQL and C# + Oracle.&lt;br /&gt;
&lt;br /&gt;
All the three are much alike (it will just change de library that you&#39;ll work with).&lt;br /&gt;
&lt;br /&gt;
Here&#39;s a Class wich a created for connect with the three Data Bases:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://dl.dropboxusercontent.com/u/23214803/Blog/Codes/connection.cs&quot; target=&quot;_blank&quot;&gt;Download Class&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: c#&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data.OracleClient;
using System.Data.SqlClient;
using System.Data;

namespace Connection
{
    public class Conexao
    {
        #region globals

        private bool _State;                    // shows connections last state
        private string _ErrorMessage;           // shows last error message
        private int _ErrorNumber;               // shows last connections last error
        private bool _CompleteCommand;          // shows last command completed with success
        
        // constantes das strings de conexão do SqlServer, Oracle e MySQL
        public const string SQL_STR_CON = &quot;yourConnectionString&quot;;
        private const string ORA_STR_CON = &quot;yourConnectionString&quot;;
        private const string MYSQL_STR_CON = &quot;yourConnectionString&quot;;

        #endregion

        #region properties

        public int ErrorNumber
        {
            get { return _ErrorNumber; }
        }
        public string ErrorDescription
        {
            get { return _ErrorMessage; }
        }
        public bool ConnectionState
        {
            get { return _State; }
        }
        public bool CompleteCommand
        {
            get { return _CompleteCommand; }
        }
        #endregion
       
        /// &lt;summary&gt;
        /// Executes a sql command with no return. Uses Transaction. 
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;myQuery&quot; /&gt;Query a ser executada. (INSERT, UPDATE, DELETE, TRUNCATE, DROP)
        /// &lt;param name=&quot;banco&quot; /&gt;SQLSERVER, ORACLE, MYSQL
        public void ExecutaNonQuery(string myQuery, string banco)
        {
            // Definir valores padrões das variaveis
            _ErrorMessage = &quot;&quot;;
            _State = false;

            // Se não for informado comando T-SQL retorno error
            if (myQuery.Length &amp;gt; 0) // Se realmente foi passado um comando a ser executado
            {
                switch (banco)
                {
                    case &quot;SQLSERVER&quot;:
                        SqlConnection sqlCon = new SqlConnection(SQL_STR_CON);
                        SqlTransaction sqlTransaction;                            
                        sqlCon.Open();
                        sqlTransaction = sqlCon.BeginTransaction();
                        SqlCommand sqlCommand = new SqlCommand(myQuery, sqlCon, sqlTransaction);
                        try
                        {
                            sqlCommand.ExecuteNonQuery();
                            sqlTransaction.Commit();
                            _State = true;
                            _CompleteCommand = true;
                        }
                        catch (SqlException sqlEx)
                        {
                            sqlTransaction.Rollback();
                            _ErrorMessage = sqlEx.Message.ToString();
                            _State = false;
                            _ErrorNumber = sqlEx.GetHashCode();
                            _CompleteCommand = false;
                        }                                                                                    
                        sqlCon.Close();
                        sqlCommand.Dispose();
                        break;
                    case &quot;ORACLE&quot;:
                        OracleConnection oraCon = new OracleConnection(ORA_STR_CON);
                        OracleTransaction oraTransaction;
                        oraCon.Open();
                        oraTransaction = oraCon.BeginTransaction();
                        OracleCommand oraCommand = new OracleCommand(myQuery, oraCon, oraTransaction);
                        try
                        {
                            oraCommand.ExecuteNonQuery();
                            oraTransaction.Commit();
                            _State = true;
                            _CompleteCommand = true;
                        }
                        catch (OracleException oraEx)
                        {
                            oraTransaction.Rollback();
                            _ErrorMessage = oraEx.Message.ToString();
                            _State = false;
                            _ErrorNumber = oraEx.GetHashCode();
                            _CompleteCommand = false;
                        }                            
                        oraCon.Close();
                        oraCommand.Dispose();
                        break;
                    case &quot;MYSQL&quot;:
                        MySqlConnection mySqlCon = new MySqlConnection(MYSQL_STR_CON);
                        MySqlTransaction mySqlTransaction;
                        mySqlCon.Open();
                        mySqlTransaction = mySqlCon.BeginTransaction();
                        MySqlCommand mySqlCommand = new MySqlCommand(myQuery, mySqlCon, mySqlTransaction);
                        try
                        {
                            mySqlCommand.ExecuteNonQuery();
                            mySqlTransaction.Commit();
                            _State = true;
                            _CompleteCommand = true;
                        }
                        catch (MySqlException myEx)
                        {
                            mySqlTransaction.Rollback();
                            _ErrorMessage = myEx.Message.ToString();
                            _State = false;
                            _ErrorNumber = myEx.GetHashCode();
                            _CompleteCommand = false;
                        }                            
                        mySqlCon.Close();
                        mySqlCommand.Dispose();
                        break;
                    default:
                        _ErrorMessage = &quot;BANCO INFORMADO INVÁLIDO&quot;;
                        break;
                }                                    
            }
        }

        /// &lt;summary&gt;
        /// Executes a sql query.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;myQuery&quot; /&gt;Query.
        /// &lt;param name=&quot;banco&quot; /&gt;SQLSERVER, ORACLE, MYSQL
        /// &lt;returns&gt;DataTable&lt;/returns&gt;
        public DataTable ExecutaReader(string myQuery, string banco)
        {
            DataTable dtResult = new DataTable();
            _ErrorMessage = &quot;&quot;;
            _State = false;
            if (myQuery.Length &amp;gt; 0)
            {
                switch (banco)
                {
                    case &quot;SQLSERVER&quot;:
                        SqlConnection sqlCon = new SqlConnection(SQL_STR_CON);                           
                        sqlCon.Open();
                        SqlCommand sqlCommand = new SqlCommand(myQuery, sqlCon);
                        try
                        {
                            SqlServerReader = sqlCommand.ExecuteReader();
                            dtResult.Load(SqlServerReader);
                            _State = true;
                            _CompleteCommand = true;
                        }
                        catch (SqlException sqlEx)
                        {
                            _ErrorMessage = sqlEx.Message.ToString();
                            _State = false;
                            _ErrorNumber = sqlEx.GetHashCode();
                            _CompleteCommand = false;
                        }                                                                                    
                        sqlCon.Close();
                        sqlCommand.Dispose();
                        break;
                    case &quot;ORACLE&quot;:
                        OracleConnection oraCon = new OracleConnection(ORA_STR_CON);
                        oraCon.Open();
                        OracleCommand oraCommand = new OracleCommand(myQuery, oraCon);
                        try
                        {
                            OraReader = oraCommand.ExecuteReader();
                            dtResult.Load(OraReader);
                            _State = true;
                            _CompleteCommand = true;
                        }
                        catch (OracleException oraEx)
                        {
                            _ErrorMessage = oraEx.Message.ToString();
                            _State = false;
                            _ErrorNumber = oraEx.GetHashCode();
                            _CompleteCommand = false;
                        }                            
                        oraCon.Close();
                        oraCommand.Dispose();
                        break;
                    case &quot;MYSQL&quot;:
                        MySqlConnection mySqlCon = new MySqlConnection(MYSQL_STR_CON);
                        mySqlCon.Open();
                        MySqlCommand mySqlCommand = new MySqlCommand(myQuery, mySqlCon);
                        try
                        {
                            MysqlReader = mySqlCommand.ExecuteReader();
                            dtResult.Load(MysqlReader);
                            _State = true;
                            _CompleteCommand = true;
                        }
                        catch (MySqlException myEx)
                        {
                            _ErrorMessage = myEx.Message.ToString();
                            _State = false;
                            _ErrorNumber = myEx.GetHashCode();
                            _CompleteCommand = false;
                        }                            
                        mySqlCon.Close();
                        mySqlCommand.Dispose();
                        break;
                    default:
                        _ErrorMessage = &quot;BANCO INFORMADO INVÁLIDO&quot;;
                        break;
                }
            }
            return dtResult;
        }

        /// &lt;summary&gt;
        /// Sql query with a single return.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;myQuery&quot; /&gt;Query
        /// &lt;param name=&quot;banco&quot; /&gt;SQLSERVER, ORACLE, MYSQL
        /// &lt;returns&gt;Object&lt;/returns&gt;
        public Object ExecutaScalar(string myQuery, string banco)
        {
            Object objResult = new Object();
            _ErrorMessage = &quot;&quot;;
            _State = false;
            if (myQuery.Length &amp;gt; 0)
            {
                switch (banco)
                {
                    case &quot;SQLSERVER&quot;:
                        SqlConnection sqlCon = new SqlConnection(SQL_STR_CON);
                        sqlCon.Open();
                        SqlCommand sqlCommand = new SqlCommand(myQuery, sqlCon);
                        try
                        {
                            objResult = sqlCommand.ExecuteScalar();
                            _State = true;
                            _CompleteCommand = true;
                        }
                        catch (SqlException sqlEx)
                        {
                            _ErrorMessage = sqlEx.Message.ToString();
                            _State = false;
                            _ErrorNumber = sqlEx.GetHashCode();
                            _CompleteCommand = false;
                        }
                        sqlCon.Close();
                        sqlCommand.Dispose();
                        break;
                    case &quot;ORACLE&quot;:
                        OracleConnection oraCon = new OracleConnection(ORA_STR_CON);
                        oraCon.Open();
                        OracleCommand oraCommand = new OracleCommand(myQuery, oraCon);
                        try
                        {
                            objResult = oraCommand.ExecuteScalar();
                            _State = true;
                            _CompleteCommand = true;
                        }
                        catch (OracleException oraEx)
                        {
                            _ErrorMessage = oraEx.Message.ToString();
                            _State = false;
                            _ErrorNumber = oraEx.GetHashCode();
                            _CompleteCommand = false;
                        }
                        oraCon.Close();
                        oraCommand.Dispose();
                        break;
                    case &quot;MYSQL&quot;:
                        MySqlConnection mySqlCon = new MySqlConnection(MYSQL_STR_CON);
                        mySqlCon.Open();
                        MySqlCommand mySqlCommand = new MySqlCommand(myQuery, mySqlCon);
                        try
                        {
                            objResult = mySqlCommand.ExecuteScalar();
                            _State = true;
                            _CompleteCommand = true;
                        }
                        catch (MySqlException myEx)
                        {
                            _ErrorMessage = myEx.Message.ToString();
                            _State = false;
                            _ErrorNumber = myEx.GetHashCode();
                            _CompleteCommand = false;
                        }
                        mySqlCon.Close();
                        mySqlCommand.Dispose();
                        break;
                    default:
                        _ErrorMessage = &quot;BANCO INFORMADO INVÁLIDO&quot;;
                        break;
                }
            }
            return objResult;
        }
    }
}
&lt;/pre&gt;
</description><link>http://prograstinate.blogspot.com/2013/07/whats-up-yeah-im-little-lazy-i-know.html</link><author>noreply@blogger.com (Nataniel)</author><thr:total>0</thr:total><georss:featurename>Narnia</georss:featurename><georss:point>90 0</georss:point><georss:box>64.4779655 -41.308594 90 41.308594</georss:box></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2061895051345547701.post-7517719836065469636</guid><pubDate>Tue, 23 Aug 2011 05:24:00 +0000</pubDate><atom:updated>2014-04-24T06:54:21.359-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Connection</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">JDBC</category><category domain="http://www.blogger.com/atom/ns#">Library</category><category domain="http://www.blogger.com/atom/ns#">MySQL</category><title>Connecting Java+MySQL [Java]</title><description>&lt;div style=&quot;text-align: justify;&quot;&gt;
Ahoy!&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This post will explain how to connect MySQL to your application Java .&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
(The IDE used was NetBeans 7.0.1)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
First of all, you need to certificate if you have the correct library for this; here, I will use the J Connector(JDBC); &amp;nbsp;for check if you have or not this library:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Right Click on &quot;Libraries&quot; in a project that you already created, click &quot;Add Library&quot;, and search for &quot;mysql jdbc driver&quot; or something that looks like thi&lt;/b&gt;s.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Don&#39;t have the library? Just go &lt;a href=&quot;http://www.mysql.com/downloads/connector/j/&quot;&gt;here&lt;/a&gt;, and download it.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;After the download ends, repeat the previous steps but instead of click &quot;Add Library&quot;, click &quot;Add JAR/Folder&quot; and then select the file that you downloaded&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
And now, a simple code for connection:&lt;/div&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/natanfrost/6a712ccf850cb3f047b0.js&quot;&gt;&lt;/script&gt;</description><link>http://prograstinate.blogspot.com/2011/08/connecting-javamysql-java.html</link><author>noreply@blogger.com (Nataniel)</author><thr:total>0</thr:total></item></channel></rss>