Friday, August 29, 2008

Attach This Code At Last

var sDate = new Date(year,month-1,day);
// get the current date based on client's computer
clock var today = new Date();
// what is the difference between the start date and today's
diff = sDate-today; // get the difference in days
diff = Math.ceil(diff/1000/60/60/24);
if (diff < 0) {
alert("Invalid Start Date. Please specify a date that is in the future and not the past.");
return false }

Checking The Dates

function validate_form() {
// Get the start date var start_date = document.form.start_date.value;
// Break up the start date - using the delimiter "/" - into an array of strings start_date = start_date.split("/") // Access each element in the array. year = start_date[2];
month = start_date[1]; day = start_date[0];
/// Some basic date validation ///
// did they enter number?
if (isNaN(day) isNaN(month) isNaN(year)) {
alert("Invalid number. Please ensure the day, month and year are valid numbers.");
return false; } // check month range
if (month <> 12) {
alert("Invalid Month. Please ensure that the month is between 1 and 12 inclusive.");
return false; } // check day range if (day <> 31) {
alert("Invalid Day. Please ensure that the day is between 1 and 31 inclusive.");
return false; }
// check day/month combination if ((month==4 month==6 month==9 month==11) && day==31) { alert("Invalid Day/Month combination. Please ensure that you have a valid day/month combination."); return false; } // check for february 29th if (month == 2) {
var isleap = (year % 4 == 0 && (year % 100 != 0 year % 400 == 0));
if (day>29 (day==29 && !isleap)) {
alert("Invalid Day. This year is not a leap year. Please enter a value less than 29 for the day.");
return false } }

Tuesday, August 26, 2008

Password Strength Meter

var bCheckNumbers = true;
var bCheckUpperCase = true;
var bCheckLowerCase = true;
var bCheckPunctuation = true;
var nPasswordLifetime = 365;
// Check passwordfunction checkPassword(strPassword){
// Reset combination countnCombinations = 0;
// Check numbersif (bCheckNumbers){
strCheck = "0123456789";
if (doesContain(strPassword, strCheck) > 0) {
nCombinations += strCheck.length; }}
// Check upper caseif (bCheckUpperCase){
strCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (doesContain(strPassword, strCheck) > 0) {
nCombinations += strCheck.length; }}
// Check lower caseif (bCheckLowerCase){
strCheck = "abcdefghijklmnopqrstuvwxyz";
if (doesContain(strPassword, strCheck) > 0) {
nCombinations += strCheck.length; }}
// Check punctuationif (bCheckPunctuation){
strCheck = ";:-_=+\//?^&!.@$£#*()%~<>{}[]";
if (doesContain(strPassword, strCheck) > 0) {
nCombinations += strCheck.length; }}
// Calculate// -- 500 tries per second => minutes var nDays = ((Math.pow(nCombinations, strPassword.length) / 500) / 2) / 86400;
// Number of days out of password lifetime settingvar nPerc = nDays / nPasswordLifetime;
return nPerc;}
// Runs password through check and then updates GUI function runPassword(strPassword, strFieldID) {// Check passwordnPerc = checkPassword(strPassword);
// Get controlsvar ctlBar = document.getElementById(strFieldID + "_bar"); var ctlText = document.getElementById(strFieldID + "_text");if (!ctlBar !ctlText)return;
// Set new widthvar nRound = Math.round(nPerc * 100);if (nRound < (strPassword.length * 5)) { nRound += strPassword.length * 5; }if (nRound > 100)nRound = 100;ctlBar.style.width = nRound + "%";
// Color and textif (nRound > 95){strText = "Very Secure";strColor = "#3bce08";}else if (nRound > 75){strText = "Secure";strColor = "orange";}else if (nRound > 50){strText = "Mediam";strColor = "#ffd801";}else{strColor = "red";strText = "Very Weak";}ctlBar.style.backgroundColor = strColor;ctlText.innerHTML = "" + strText + "";}
// Checks a string for a list of charactersfunction doesContain(strPassword, strCheck){nCount = 0;
for (i = 0; i <> -1) { nCount++; } }
return nCount; }

getting Clob Out From Db

import java.io.File;
import java.io.FileWriter;
import java.io.*;
import java.sql.*;
public class ClobOut {
private static String url = "jdbc:oracle:thin:@192.168.100.1:1521:server";
private static String username = "scott";
private static String password = "tiger";
public static void main(String[] args) throws Exception {
Connection conn = null; try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, username, password);
DataInputStream din=new DataInputStream(System.in);
System.out.println("Enter The File_No"); int num=Integer.parseInt(din.readLine());
String sql = "SELECT name, description, data FROM documents where file_no="+num+""; PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
String name = resultSet.getString(1);
System.out.println("Name = " + name);
String description = resultSet.getString(2);
System.out.println("Description = " + description);
File data = new File("C:/getOut.xlsx" );
//System.out.println(data.length());
// // Get the character stream of our CLOB data //
Reader reader = resultSet.getCharacterStream(3);
FileWriter writer = new FileWriter(data);
char[] buffer = new char[1];
while (reader.read(buffer) > 0) {
writer.write(buffer); }
writer.close();
} }
catch(Exception e){
e.printStackTrace(); } }}

Inserting Clob Type Into Database

import java.io.File;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class ClobIn {
private static String url = "jdbc:oracle:thin:@192.168.100.1:1521:server";
private static String username = "scott";
private static String password = "tiger";
public static void main(String[] args) throws Exception {
Connection conn = null;
FileReader reader = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, username, password);
// conn.setAutoCommit(false);
String sql = "INSERT INTO documents (name, description, data,file_no) VALUES (?, ?, ?,?)"; PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, "Xcel");
stmt.setString(2, "Xcel");
File data = new File("C:/Book1.xlsx");
reader = new FileReader(data);
stmt.setCharacterStream(3, reader, (int) data.length());
stmt.setInt(4,2);
stmt.execute();
// conn.commit();
} catch (SQLException e) {
e.printStackTrace(); } }}

Monday, August 18, 2008

Code For Retrving The Image Using getBinaryStream()

import java.io.*;
import java.sql.*;
public class NewCodeGetImg{
static PreparedStatement pssel;
static ResultSet rs;
public static void main(String s[]) throws Exception {
// crepssel(); // pssel.setString(1, name);
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.100.1:1521:server","bond","bond");
pssel = con.prepareStatement("select image from img where img_no=30");
rs = pssel.executeQuery();
while (rs.next()) {
//File f = new File(path, rs.getString(1));
FileOutputStream fs = null;
InputStream bs = null;
fs = new FileOutputStream("New1.jpg");
bs = rs.getBinaryStream(1);
byte[] buf = new byte[16384];
int bytes;
while ((bytes = bs.read(buf)) != -1) {
fs.write(buf, 0, bytes); } } }}

Code For Retriving The Image

import java.sql.*;
import java.io.*;
public class getImage{
public static void main(String s1[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.100.1:1521:server","bond","bond");
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select * from img where img_no=30");
if(rs.next()){ Blob b =rs.getBlob(1);
byte b1[]=b.getBytes(1,(int)b.length());//new byte[(int)b.length()]; //InputStream in=photo.getBinaryStream();
OutputStream fout=new FileOutputStream("sample1.jpg");
fout.write(b1); }*/ } }*/ } catch(Exception e){ e.printStackTrace(); }}}

Code For Storing The image

import java.sql.*;
import java.io.*;
public class inimg{
public static void main(String s1[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.100.1:1521:server","bond","bond");
PreparedStatement s=con.prepareStatement("insert into img values(?,?)");
File f=new File("C:/DanielCore/Dark Night/5221667.jpg");
System.out.println("Done");
FileInputStream fin=new FileInputStream(f);
System.out.println("Done");
s.setBinaryStream(1,fin,(int)f.length());
s.setInt(2,40); System.out.println("Done");
s.executeUpdate(); System.out.println("Done");
}
catch(Exception e){
e.printStackTrace(); }
}}