ss_blog_claim=a37b70f67cd872812717e1fce7e83301
Latest Posts »
Latest Comments »
Popular Posts »

Writing SQL statement with Loop Objects

Written by techieDan on March 15, 2008 – 12:19 am

Coding have never been the same!!! Some bad habits when writing codes which are redundant

String[] special = {"a1","a2","a3","a4"};  

Connection con = null;  

PreparedStatement stmt = null;  

PreparedStatement stmt2 = null;  

ResultSet rs = null;  

ResultSet rs2 = null;  

Class.forName ("com.mysql.jdbc.Driver")  

conn = DriverManager.getConnection (url, userName, password);  

String SQL_QUERY = " SELECT count(*) FROM tblABC WHERE " +
" name_tennis LIKE = ? ";  

String SQL_QUERY2 = " SELECT count(*) FROM tblABC WHERE " +
" name_swimwear LIKE = ? ";  

stmt = con.prepareStatement(SQL_QUERY);  

stmt2 = con.prepareStatement(SQL_QUERY2);  

for (int i=0;i<special[i].length;i++) {  

      stmt.setString(1,special[i]);  

      rs = stmt.executeQuery();  

      if (rs.next()) {  

         /* More work here */  

      }  

}  

for (int i=0;ii<special[i].length;i++) {  

stmt2.setString(1,special[i]);  

      rs2 = stmt2.executeQuery();  

      if (rs2.next()) {  

         /* More work here */  

      }  

}

The above is a very bad example of coding. It might work, and run smoothly but it’s really bad coding. What one should do is to not to let the code be redundant. For example, put both statements into one the loop.

for (int i=0;i<special[i].length;i++) {  

      stmt.setString(1,special[i]);  

      rs = stmt.executeQuery();  

      if (rs.next()) {  

         /* More work here */  

      }      stmt2.setString(1,special[i]);  

      rs2 = stmt2.executeQuery();  

      if (rs2.next()) {  

         /* More work here */  

      }  

}

What’s the use of this? Well, iif you have an object or rather a Bean to set into, you don’t have to loop and reloop. All can be done in the same loop. Well, hope this brings about some bad habits of coding java.


Tags: , ,
Posted in SQL, java | No Comments »

MySQL ownership Taken Over

Written by techieDan on January 17, 2008 – 12:33 pm

MySQL logoHmm.. shocking news. It seems that the free open source MySQL database has now been bought over by SUN. Yes, Sun, the creator of Java which is famous for it’s compile once run everywhere (basically platform independent).

In terms of news, with an astonishing figure of $1,000,000,000 or in literal translation 1 Billion dollars. That’s an astonishing figure. Looks like all the big players in the Internet market are buying over stuffs.

“The combination of MySQL and Sun represents an enormous opportunity for users and organizations of all sizes seeking innovation, growth and choice,” said Marten Mickos, CEO, MySQL.

Sun Microsystems LogoSun’s ever many Software will integrate with MySQL. The breakdown of the $1 billion can seperate in terms of $800 million in exchange of MySQL stock and approximated $200 million in other options. With this news, now not only with the long lasting partnership of Sun Microsystems and Oracle but also with an additional new database to integrate together.

“We are going to keep investing in that and keep doing that,” he said. “It is vital to our customers. It is vital to our business, but we can also use that expertise and share that expertise to optimize MySQL technology to run on Sun systems as well as Linux and Windows systems.” says Rich Green, executive Vice President of Sun Microsystems Software.


Tags: , ,
Posted in News | No Comments »