Tuesday, 26 February 2013

Retrieving image from database

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
    Connection connection = null;
    String connectionURL = "jdbc:mysql://localhost:3306/test";
    ResultSet rs = null;
    PreparedStatement psmnt = null;        
    InputStream sImage;
    try
{
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        connection = DriverManager.getConnection(connectionURL, "root", "");
        psmnt = connection.prepareStatement("SELECT imagefile FROM imageupload WHERE id = ?");
        psmnt.setString(1, "4");
        rs = psmnt.executeQuery();
   if(rs.next())
{
            byte[] bytearray = new byte[1048576];
            int size=0;
            sImage = rs.getBinaryStream(1);
            response.setContentType("image/jpeg");      
            while((size=sImage.read(bytearray))!= -1 )
            {
                response.getOutputStream().write(bytearray,0,size);
}
}
}
    catch(Exception ex)
{
out.println("error :"+ex);
    }
%>

<!-- Table Structure

CREATE TABLE `imageupload` (
`id` bigint(20) NOT NULL auto_increment,
`imagefile` blob NOT NULL,
PRIMARY KEY (`id`)
)

-->

Thursday, 21 February 2013

Hide and expand in html


<script language="javascript">
function toggle5(showHideDiv, switchImgTag)
{
        var ele = document.getElementById(showHideDiv);
        var imageEle = document.getElementById(switchImgTag);
        if(ele.style.display == "block")
{
                ele.style.display = "none";
imageEle.innerHTML = '<img src="C:/Users/Tiara/Desktop/plus.png" height=15 width=15>';
        }
        else
{
                ele.style.display = "block";
                imageEle.innerHTML = '<img src="C:/Users/Tiara/Desktop/minus.png" height=15 width=15>';
        }
}
</script>

<div id="headerDivImg">
    <div id="titleTextImg">Let's use images!</div>
    <a id="imageDivLink" href="javascript:toggle5('contentDivImg', 'imageDivLink');">
<img src="C:\Users\Tiara\Desktop\minus.png" height=15 width=15>
</a>
</div>
<div id="contentDivImg" style="display: block;">This demo uses plus and minus images for hiding and showing your div dynamically.</div>

Monday, 11 February 2013

Page redirect after a certain time in html


<html>
<head>
<meta http-equiv="refresh" content="10; URL=http://www.yahoo.com" />
<title>HTML Redirect</title>
</head>

<body>
Wait Redirecting ....
</body>
</html>

DBT - Models

Models are where your developers spend most of their time within a dbt environment. Models are primarily written as a select statement and ...