<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Binary Tides &#187; sql</title>
	<atom:link href="http://www.binarytides.com/blog/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.binarytides.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 24 Jul 2010 05:31:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Change column / field order in OpenOffice Base ( HSQL )</title>
		<link>http://www.binarytides.com/blog/change-column-field-order-in-openoffice-base-hsql/</link>
		<comments>http://www.binarytides.com/blog/change-column-field-order-in-openoffice-base-hsql/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 12:07:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[openoffice]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=34</guid>
		<description><![CDATA[Altering the sequence of fields of a table was a feature I was looking for in OpenOffice Base. It is not directly possible to drag the columns or fields and alter their sequence.
A SQL workaround can do the same thing.

If the sequence of fields is :
name , email , address , phone
and phone is to [...]]]></description>
			<content:encoded><![CDATA[<p>Altering the sequence of fields of a table was a feature I was looking for in OpenOffice Base. It is not directly possible to drag the columns or fields and alter their sequence.</p>
<p>A SQL workaround can do the same thing.</p>
<p><span id="more-34"></span></p>
<p>If the sequence of fields is :</p>
<p>name , email , address , phone</p>
<p>and phone is to be brought before address like this :</p>
<p>name , email , phone , address</p>
<p>then the sql for this should be</p>
<p>1. ALTER TABLE &#8220;tablename&#8221; ADD COLUMN &#8220;phone2&#8243; INTEGER BEFORE &#8220;address&#8221;</p>
<p>2. UPDATE &#8220;tablename&#8221; SET &#8220;phone2&#8243; = &#8220;phone&#8221;</p>
<p>3. ALTER TABLE &#8220;tablename&#8221; DROP COLUMN &#8220;phone&#8221;</p>
<p>4. ALTER TABLE &#8220;tablename&#8221; ALTER COLUMN &#8220;phone2&#8243; RENAME TO &#8220;phone&#8221;</p>
<p>Then View > Refresh Tables in the top menu. And open the table again for viewing.<br />The sequence should now be name , email , phone , address</p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=34&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/change-column-field-order-in-openoffice-base-hsql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Execute an SQL Script in JDBC</title>
		<link>http://www.binarytides.com/blog/execute-an-sql-script-in-jdbc/</link>
		<comments>http://www.binarytides.com/blog/execute-an-sql-script-in-jdbc/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 14:21:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=24</guid>
		<description><![CDATA[The SQL Script should have comments starting with &#8211; or &#8212; only on new lines and each command should end with a ; .
Reading a sql file and putting all of it in a string variable and feeding to the execute command would result in an exception. All instructions must be executed individually. A proper [...]]]></description>
			<content:encoded><![CDATA[<p>The SQL Script should have comments starting with &#8211; or &#8212; only on new lines and each command should end with a ; .</p>
<p>Reading a sql file and putting all of it in a string variable and feeding to the execute command would result in an exception. All instructions must be executed individually. A proper sql script should have all instructions starting on a newline and all comments on a newline. Start with an empty string. Start reading the lines ; if a line has a &#8211; as the first character then continue else add it to the query string. Now if the last character of the query string is a ; then a command is complete so execute the query and make the query string empty and loop up. Thats it</p>
<p><span id="more-24"></span></p>
<p>Executing an sql script in jdbc with the following code should work &#8230;</p>
<pre class="brush: java;">
//Now read line bye line
String thisLine, sqlQuery;
try {
    sqlQuery = &quot;&quot;;
    while ((thisLine = d.readLine()) != null)
    {
        //Skip comments and empty lines
        if(thisLine.length() &gt; 0 &amp;&amp; thisLine.charAt(0) == '-' || thisLine.length() == 0 )
            continue;
        sqlQuery = sqlQuery + &quot; &quot; + thisLine;
        //If one command complete
        if(sqlQuery.charAt(sqlQuery.length() - 1) == ';') {
            sqlQuery = sqlQuery.replace(';' , ' '); //Remove the ; since jdbc complains
            try {
                stmt.execute(sqlQuery);
            }
            catch(SQLException ex) {
                JOptionPane.showMessageDialog(null, &quot;Error Creating the SQL Database : &quot; + ex.getMessage());
            }
            catch(Exception ex) {
                JOptionPane.showMessageDialog(null, &quot;Error Creating the SQL Database : &quot; + ex.getMessage());
            }
            sqlQuery = &quot;&quot;;
        }
    }
}
catch(IOException ex) {
}
catch(Exception ex) {
    JOptionPane.showMessageDialog(null, &quot;Error Creating the SQL Database : &quot; + ex.getMessage());
}
</pre>
<p>where d could be BufferedReader and c could be a Statement object.</p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=24&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/execute-an-sql-script-in-jdbc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
