HTA/HTML/VBScript/AD - Extract user information from AD using VBscript - html

I'm trying to create my first application. I want to create a script that extracts some user's properties from Active Directory. I've created an HTA application, but it doesn't work.
I really need some support from you.
Thanks.
And here is HTML code [for HTA app
Here is script details:
<script type="VBscript">
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = ("ADsDSOObject")
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
objCommand.Properties("SearchScope") = 2
objCommand.CommandText = "SELECT userWorkstations,sAMAccountName,Mail,name,DisplayName,distinguishedName,LastLogonDate, FROM 'LDAP://dc=NESTLE,dc=com' WHERE objectCategory='user' AND displayname='" & VaR5 & "'"
Set objRecordSet = objCommand.Execute
</script>
<hta:application
applicationname="ADUCUserGrab"
border="thin"
borderstyle="normal"
caption="ADUC User Grab"
contextmenu="yes"
icon="aduc_sm.ico"
maximizebutton="no"
minimizebutton="yes"
navigable="yes"
scroll="yes"
selection="yes"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
version="1.0"
windowstate="normal"
>
</head>
And here is HTML code [for .hta app]:
<body topmargin="1" leftmargin="0" rightmargin="0" bottommargin="1" bgcolor="#000080" text="#FFFFFF">
<table border="0" width="640" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="top" height="110" bgcolor="#000080">
<i>Enter the <u>userid</u> or <u>last name</u> below and click appropriate search.</i><br>
<input type="text" name="StrUserid" size="20">
<input id=idsearchbutton class="button" type="button" value="Search On UserID" name="userid" onClick="SearchScope">
</td>
</tr>
<tr>
<td valign="top" height="300" bgcolor="#000080">
<Div id="BaseUserInfo"></Div>
<br>
<table border="0" width="100%" cellspacing="1" cellpadding="0">
<tr>
<td width="60%" valign="top"><Div id="AddUserInfo"></Div></td>
<td width="40%" valign="top"><Div id="AccUserStatus"></Div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" height="70" bgcolor="#000080">
<div id="AdditionalOptions"></div>
</td>
</tr>
</table>

If this is for your first HTA app experience then you`re aiming too high. Simplify mightily until your button pops up a "Hello World" message, then elaborate. Make the message include something pulled from a free text field, build gradually.

now it should work :-)
<html>
<head>
<hta:application
applicationname="ADUCUserGrab"
border="thin"
borderstyle="normal"
caption="ADUC User Grab"
contextmenu="yes"
icon="aduc_sm.ico"
maximizebutton="no"
minimizebutton="yes"
navigable="yes"
scroll="yes"
selection="yes"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
version="1.0"
windowstate="normal"
>
</head>
<body topmargin="1" leftmargin="0" rightmargin="0" bottommargin="1" bgcolor="#000080" text="#FFFFFF">
<script language="javascript">
var adStateOpen = 1;
var ADS_SCOPE_SUBTREE = 2;
function SearchScope () {
var e;
try {
var objConnection = new ActiveXObject( "ADODB.Connection" );
objConnection.Provider = "ADsDSOObject";
//objConnection.Properties( "User ID" ) = credUser;
//objConnection.Properties( "Password" ) = credPwd;
//objConnection.Properties( "Encrypt Password" ) = true;
objConnection.Open( );
if ( objConnection.State == adStateOpen ) {
var objCommand = new ActiveXObject( "ADODB.Command" );
objCommand.ActiveConnection = objConnection;
//objCommand.Properties( "Page Size" ) = 1000;
objCommand.Properties( "Searchscope" ) = ADS_SCOPE_SUBTREE;
objCommand.CommandText = (
"SELECT "
+ "CN, distinguishedName, sAMAccountName, description, userAccountControl"
+ " FROM "
+ "'LDAP://dc=NESTLE,dc=com'"
+ " WHERE "
+ "objectCategory='user'"
+ " AND ("
+ "sAMAccountName='" + document.getElementById( "StrUserid" ).value + "'"
+ " OR "
+ "displayname LIKE '%" + document.getElementById( "StrUserid" ).value + "%'"
+ ")"
);
var objRecordSet = objCommand.Execute( );
if ( !objRecordSet.EOF ) {
alert( objRecordSet.Fields("CN").Value );
}
}
} catch (e) {
// log error
alert( e.description );
}
}
</script>
<table border="0" width="640" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="top" height="110" bgcolor="#000080">
<i>Enter the <u>userid</u> or <u>last name</u> below and click appropriate search.</i><br>
<input type="text" id="StrUserid" name="StrUserid" size="20">
<input id=idsearchbutton class="button" type="button" value="Search On UserID" onClick="SearchScope()">
</td>
</tr>
<tr>
<td valign="top" height="300" bgcolor="#000080">
<Div id="BaseUserInfo"></Div>
<br>
<table border="0" width="100%" cellspacing="1" cellpadding="0">
<tr>
<td width="60%" valign="top"><Div id="AddUserInfo"></Div></td>
<td width="40%" valign="top"><Div id="AccUserStatus"></Div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" height="70" bgcolor="#000080">
<div id="AdditionalOptions"></div>
</td>
</tr>
</table>
</body>
</html>

Related

Accessing Yahoo YQL finance query

I am receiving an error when trying to use the yql statement. The console says there is a syntax error, but I do not see an error. I have posted all of the code so it can be copy and pasted to repeat the error.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Finances</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script language="JavaScript">
function start(){
getData();
// document.getElementById('link1').click();
}
function getData() {
var url = "http://query.yahooapis.com/v1/public/yql";
var symbol = $("#symbol").val();
var dateInput = $("#dateInput").val();
var data = encodeURIComponent("select * from yahoo.finance.historicaldata where symbol = '"symbol"' and startDate = '"dateInput"' and endDate = '"dateInput"'");
$.getJSON(url, '?q=' + data + "&diagnostics=true&env=store://datatables.org/alltableswithkeys")
.done(function (data) {
$("#name").text(data.query.results.quote.Symbol);
$("#date").text(data.query.results.quote.Date);
$("#close").text( data.query.results.quote.Close);
}).fail(function (jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
$("#result").text('Request failed: ' + err);
});
}
function SendRequest()
{
getData();
// document.getElementById('link1').click();
}
function CheckEnter(e)
{
if ((e.keyCode && e.keyCode==13) || (e.which && e.which==13)) {
return SendRequest();
}
return true;
}
</script>
</head>
<body style="margin: 0px;" bgcolor="#678fc2" onload="start();">
<table width="90%" border="0" cellpadding="0" cellspacing="0" align="center">
<tbody>
<tr valign="top">
<td class="normalText" align="left">
<label>Date</label>
<input name="date" id="dateInput" value="2010-07-17" type="text" />
<br/>
<label>Ticker Symbol</label>
<input name="txtQuote" id="symbol" onkeypress="return CheckEnter(event);" value="YHOO" type="text" />
<input name="button" type="button" id="btnQuote" onclick="return SendRequest();" value="Get Quotes" />
<br />
<div id="service" style="padding:10px 0;">
<table style="border: 1px solid black;" width="770">
<tbody>
<tr style="font-size: 14px; font-family: Arial,Helvetica,sans-serif; font-weight: bold; padding: 0px 2px;">
<td>Symbol</td>
<td>Date</td>
<td>Closing Price</td>
</tr>
<tr style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; padding: 0px 2px;">
<td id="name"></td>
<td id="date"></td>
<td id="close"></td>
</tr>
</tbody>
</table>
<br /><br />
</div>
</td>
</tr>
</tbody>
I found the error I was having. This is the correct line now:
var data = encodeURIComponent("select * from yahoo.finance.historicaldata where symbol = '" + symbol + "' and startDate = '" + dateInput + "' and endDate = '" + dateInput + "'");

Delphi Twebbrowser Identify html element id

All, we have an RFID application that is web based. We are trying to make display boards across our facility that shows information. I'm trying to make the webpage auto-login but I'm not having any luck. I've tried enumerating all tags/elements on the page but I'm not having any luck.
Access violation with the line below (because the element j_username isn't found, but it's clearly in the html snippet. I know I'm missing something simple. Can someone please help?
WebBrowser1.OleObject.Document.GetElementByID('j_username').
setAttribute('value', 'dempseyw');
here is the login code from the page I am trying to automate.
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>MobileView</title>
<style type="text/css">
.loginTextCss{
padding:0 0 0 22;
}
#javax_faces_developmentstage_messages{
display: none;
}
</style></head><body onload="document.getElementById('j_username').focus()" style="margin:0px; overflow: hidden;">
<div style="display:none" id="notLogedInMarker"></div>
<form action="http://dmh-rfidweb/asset-manager-web/j_spring_security_check" method="post">
<table border="0" align="center" height="100%" width="687" cellpadding="0" cellspacing="0">
<tr>
<td height="50%" valign="top">
<img src="http://dmh-rfidweb/asset-manager-web/images/spacer.gif" border="0" width="1" height="1" />
</td>
</tr>
<tr>
<td class="directionCss"><span style="font-size:12px; font-weight: bold; color: #0000FF; font-family:arial"></span>
</td>
</tr>
<tr>
<td height="427" valign="top" background="http://dmh-rfidweb/asset-manager-web/images/branding/healthcare/bg_login.jpg" style="background-repeat:no-repeat; color:#000000; font-family:arial, Helvetica, sans-serif; font-size:14px;">
<div style="width:200px;height:150px;float:right;">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td style="padding:3 6 0 22;" valign="bottom">
<br clear="all" />
<a href="https://www.stanleyhealthcare.com/" target="new"><img src="http://dmh-rfidweb/asset-manager-web/images/branding/healthcare/logo_mobileview.gif" style="border:1; hspace:2;" />
</a>
</td>
</tr>
</table>
</div>
<br clear="all" />
<div style="height:50; padding:0 0 0 15;">
<div style="height:10;"></div>
</div>
<div class="loginTextCss"><label for="j_username">User Name:</label>
<br /><input id="j_username" name="j_username" type="text" value="" style="font-size:16px; width:170px;" />
<br />
<br /><label for="j_password">Password:</label>
<br /><input type="password" id="j_password" name="j_password" value="" style="font-size:16px; width:170px;" />
<br />
<div style="font-size:11;">
<input id="rememberMe" type="checkbox" name="_spring_security_remember_me" title="Remember me on this computer" checked="Checked" />
<label for="rememberMe" title="Remember me on this computer">Remember me on this computer</label>
</div>
<div style="padding-left:112px;padding-top:20;">
<input type="submit" value="Log In" style="padding:3 10 3 10;color:#000000; font-family:arial, Helvetica, sans-serif;font-size:14px;" />
</div>
</div>
</td>
</tr>
<tr>
<td height="50%" valign="top">
<img src="http://dmh-rfidweb/asset-manager-web/images/spacer.gif" border="0" width="1" height="1" />
</td>
</tr>
</table>
</form></body>
</html>
You have to locate the form, then you can locate and set the value of the element within the form.
Navigate to the webpage with TWebBrowser, then try the following. Note, this does not consider the possibility of frames.
function GetFormByNumber(document: IHTMLDocument2; formNumber: integer)
: IHTMLFormElement;
var
Forms: IHTMLElementCollection;
begin
Forms := document.Forms as IHTMLElementCollection;
if formNumber < Forms.Length then
Result := Forms.item(formNumber, '') as IHTMLFormElement
else
Result := nil;
end;
procedure SetFieldValue(theForm: IHTMLFormElement; const fieldName: string;
const newValue: string);
var
field: IHTMLElement;
inputField: IHTMLInputElement;
selectField: IHTMLSelectElement;
textField: IHTMLTextAreaElement;
begin
field := theForm.item(fieldName, '') as IHTMLElement;
if Assigned(field) then
begin
if field.tagName = 'INPUT' then
begin
inputField := field as IHTMLInputElement;
inputField.Value := newValue;
end
else if field.tagName = 'SELECT' then
begin
selectField := field as IHTMLSelectElement;
selectField.Value := newValue;
end
else if field.tagName = 'TEXTAREA' then
begin
textField := field as IHTMLTextAreaElement;
textField.Value := newValue;
end;
end
else
raise Exception.Create('HTML Field not found: ' + fieldName);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
doc: IHTMLDocument2;
theForm: IHTMLFormElement;
begin
doc := WebBrowser.Document as IHTMLDocument2;
theForm := GetFormByNumber(doc, 0);
SetFieldValue(theForm,'j_username','dempseyw');
SetFieldValue(theForm,'j_password','pw');
theForm.submit;
end;

HTML creating space around input text?

page is available here: http://macrorevolution.com/calculators/bmr/
How do I go about creating space after my input[text] box. For example, I want to create 1px spacing between the input box and "Years","ft","In"."k/cal per day".
I tried using .ipadding but that didn't work so ignore it. Also, how can I shift all of the input boxes closer to "Age", "Height", "weight"?
I am new to html/css.
<?php
$answer = "";
$agev = "";
$feetv = "";
$inchesv = "";
$weightv = "";
$sex = "";
if(isset($_POST['agev']) && isset($_POST['feetv']) && isset($_POST['inchesv']) && isset($_POST['weightv']) && isset($_POST['sex'])) {
$agev = $_POST['agev'];
$feetv = $_POST['feetv'];
$inchesv = $_POST['inchesv'];
$weightv = $_POST['weightv'];
$sex = $_POST['sex'];
$totalheightv = $inchesv + ($feetv*12);
$heightcm = $totalheightv*2.54;
$weightkg = $weightv/2.2;
if($sex=='male') $answer = round((66.47 + (13.75*$weightkg) + (5*$heightcm) - (6.75*$agev)),0);
if($sex=='female') $answer = round((665.09 + (9.56*$weightkg) + (1.84*$heightcm) - (4.67*$agev)),0);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<title>Basal Metabolic Rate Calculator</title>
<style>
table {
border: 30px;
font-size:13px;
font-family: 'PT Sans', sans-serif;
background-color:#FFFFFF;
}
tr.spaceUnder > td
{
padding:0em 1em 1em 0em;
}
p.ss {
font-size:30px;
}
.ipadding {
padding:1px;
}
</style>
</head>
<body>
<div class="box pt20">
<p class="ss">MacroRevolution BMR Calculator</p><br>
<table width='80%' style="margin: 0 auto;">
<tr class="spaceUnder">
<td colspan="4">
BMR = Basal Metabolic Rate (similar to RMR = Resting Metabolic Rate). Your BMR represents the number of calories your body burns at rest. Regular routine of cardiovascular exercise can increase your BMR, improving your health and fitness when your body's ability to burn energy gradually slows down.
</td>
</tr>
</table>
<form method='post' action=''>
<table width='80%' style="margin: 0 auto;">
<tr class="spaceUnder">
<td>Age:</td>
<td><input type='text' name='agev' value="<?php echo $agev; ?>"/>Years</td>
</tr>
<tr class="spaceUnder">
<td>Height:</td>
<td align="justify"><input type='text' name='feetv' value="<?php echo $feetv; ?>"/>Ft<p> </p>
<input type='text' name='inchesv' value="<?php echo $inchesv; ?>"/>In</td>
</tr>
<tr class="spaceUnder">
<td>Weight:</td>
<td align="left"><input type='text' name='weightv' value="<?php echo $weightv; ?>"/>lbs</td>
</tr>
<tr class="spaceUnder">
<td colspan="2"><input type='radio' name='sex' value='male'>Male
<input type='radio' name='sex' value='female'>Female</td>
</tr>
<tr class="spaceUnder">
<td colspan="2"><input type='submit' class="button highlight small" value='Calculate'/></td>
</tr>
<tr class="spaceUnder">
<td colspan="2">Your BMR is <input type='text' style="width: 50px;" value='<?php echo $answer?>' />k/cal per day </td>
</tr>
</table>
</form>
<table border='0' width='80%' style="margin: 0 auto;">
<td colspan="4">
Formula for BMR
If you want to manually calculate your BMR, use the (Harris-Benedict formula) <br> below. <br><br>
Men: BMR=66.47+ (13.75 x W) + (5.0 x H) - (6.75 x A) <br>
Women: BMR=665.09 + (9.56 x W) + (1.84 x H) - (4.67 x A) <br><br>
W = Weight in kilograms (lbs/2.2)<br>
H = Height in centimeters (inches x 2.54)<br>
A = Age in years <br><br><br>
</td>
</table>
</div>
</body>
</html>
put a margn on the right side.
input {
margin-right:5px;
}
So many ways, one is as:
input[type="text"] {margin-right:1px;}
input[type="radio"] {margin-right:5px;}
.spaceUnder td:first-child {width:50px;}
Use :
input{
margin-right:1px;
}
For bringing textboxes near to the label put them in the same td.
See this Fiddle
just follow the image and create a new css rule and update css rule.Hope it will be helpful!
Step: 1
Step:2

HTML table settings not working

I'm trying to tamper with my html table settings to set borders but I think my syntax is wrong. I've looked around online and tried multiple things with no success. Any suggestions?
For example, this code is applied to the first table but does not appear correctly on page.
<table BORDER="30" CELLPADDING="10" CELLSPACING="3" BORDERCOLOR="00FF00" width='80%' style="margin: 0 auto;">
</table>
HTML code is applied here: http://macrorevolution.com/calculators/bmr/
The only table settings that seem to work are "width='80%' style="margin: 0 auto;""
<?php
$answer = "";
$agev = "";
$feetv = "";
$inchesv = "";
$weightv = "";
$sex = "";
if(isset($_POST['agev']) && isset($_POST['feetv']) && isset($_POST['inchesv']) && isset($_POST['weightv']) && isset($_POST['sex'])) {
$agev = $_POST['agev'];
$feetv = $_POST['feetv'];
$inchesv = $_POST['inchesv'];
$weightv = $_POST['weightv'];
$sex = $_POST['sex'];
$totalheightv = $inchesv + ($feetv*12);
$heightcm = $totalheightv*2.54;
$weightkg = $weightv/2.2;
if($sex=='male') $answer = 66.47 + (13.75*$weightkg) + (5*$heightcm) - (6.75*$agev);
if($sex=='female') $answer = 665.09 + (9.56*$weightkg) + (1.84*$heightcm) - (4.67*$agev);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Basal Metabolic Rate Calculator</title>
</head>
<body>
<div class="box pt20">
<table BORDER="30" CELLPADDING="10" CELLSPACING="3" BORDERCOLOR="00FF00" width='80%' style="margin: 0 auto;">
<td colspan="4">
<h4 style="background: #99FF99;">
<strong>BMR = Basal Metabolic Rate</strong> (similar to RMR = Resting Metabolic Rate). Your BMR represents the number of calories your body burns at rest. Regular routine of cardiovascular exercise can increase your BMR, improving your health and fitness when your body's ability to burn energy gradually slows down.
</h4>
</td>
</table>
<form method='post' action=''>
<table border='5' width='80%' font-family:Georgia; font-size:1; class="table" style="margin: 0 auto;" bgcolor="FFFFFF">
<tr class="calcheading">
<td colspan="2"><font size="10">MacroRevolution BMR Calculator</font></td>
</tr>
<tr class="calcrow">
<td>Age:</td>
<td><input type='text' name='agev' value="<?php echo $agev; ?>"/>Years</td>
</tr>
<tr class="calcrow2">
<td>Height:</td>
<td align="justify"><input type='text' name='feetv' value="<?php echo $feetv; ?>"/>Ft<input type='text' name='inchesv' value="<?php echo $inchesv; ?>"/>In</td>
</tr>
<tr class="calcrow">
<td>Weight:</td>
<td align="left"><input type='text' name='weightv' value="<?php echo $weightv; ?>"/>lbs</td>
</tr>
<tr class="gender">
<td colspan="2"><input type='radio' name='sex' value='male'>Male
<input type='radio' name='sex' value='female'>Female</td>
</tr>
<tr class="submit">
<td colspan="2"><input type='submit' class="button highlight small" value='Calculate'/></td>
</tr>
<tr class="calcrow">
<td colspan="2">Your BMR is <span style="background-color: #00CC33"><?php echo $answer?></span></td>
</tr>
</table>
</form>
<table border='0' width='80%' class="table" align="center" style="margin: 0 auto;">
<td colspan="4">
<h2 style="background: #99FF66;">Formula for BMR</h2>
<h4 style="background: #99FF66;">
If you want to manually calculate your BMR, use the (Harris-Benedict formula) <br> below. <br><br>
Men: BMR=66.47+ (13.75 x W) + (5.0 x H) - (6.75 x A) <br>
Women: BMR=665.09 + (9.56 x W) + (1.84 x H) - (4.67 x A) <br><br>
W = Weight in kilograms (lbs/2.2)<br>
H = Height in centimeters (inches x 2.54)<br>
A = Age in years
</h4>
</td>
</table>
</div>
</body>
</html>
<!-- ///////////////////////////////////////////////////////////////////////////////////////////-->
Avoid HTML attributes like border="30" cellpadding="10" cellspacing="3" bordercolor="#00ff00" and use CSS instead:
<style>
table {
border: 30px solid #00ff00;
}
</style>
Even better, move the styles to another file
<link rel="stylesheet" type="text/css" href="stylesheet.css">

How to get data between two dates?

I am having a date picker issue in a jsp file.
When i click on hyperlink in Allmeters.jsp file,it will open the meteridinfo.jsp. In this file i have one label called meterid. I get this meterid value from allmeters.jsp and also i have two fields called fromdate and todate. By using these dates i am getting data from mysql table but the problem is when i choose fromdate as 2012-05-1 and todate as 2012-05-11 it is not retreiving the data but when i change todate as 2012-05-31 then it is displaying data from mysql table,it means when i select the lastdate in a month as todate then only it is coming.Please help me.
The codings of AllMeters.jsp is given below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%#page import="java.sql.*"%>
<html>
<head>
<title>All Meter's</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
td{FONT: 13px Arial,sans-serif;}
th{FONT:bold 13px Arial,sans-serif;color:white;background-color:#3366ff}
input{FONT: 13px Arial,sans-serif;border: solid 1;}
select{font: 13px Arial,sans-serif}
#button{cursor:hand}
A:hover {COLOR: red}</style>
<script type="text/javascript">
window.history.forward();
function noback() { window.history.forward(); }
</script>
</head>
<body>
<table border=1 style="" width="100%" align="center" cellpadding="5" cellspacing="0">
<tr>
<th>S No</th>
<th>Meter ID</th>
<th>Consumer ID</th>
<th>Consumer Name</th>
<th>Reading</th>
<th> Date</th>
<th>Time</th>
<th>Status</th>
<th>Sub Zone</th>
<th>Zone</th></tr>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/suwatermeter","root","sumith");
Statement st=con.createStatement();
int mid;
int SNo=1;
ResultSet rs=st.executeQuery("select * from Meter_List");
while(rs.next()){
%>
<tr><td align="center" bgcolor="#ededed"><%=SNo%></td><td align="center" bgcolor="#ededed"><%=rs.getInt("Meterid")%></td><td align="center" bgcolor="#ededed"><%=rs.getInt("Consumerid")%></td><td bgcolor="#ededed"><%=rs.getString("Consumername")%></td><td align="center" bgcolor="#ededed"><%=rs.getInt("LastReading")%></td><td align="center" bgcolor="#ededed"><%=rs.getDate("Date")%></td><td align="center" bgcolor="#ededed"><%=rs.getTime("Time")%></td><td align="center" bgcolor="#ededed"><%=rs.getString("Status")%></td><td align="center" bgcolor="#ededed"><%=rs.getString("Subzone")%></td><td align="center" bgcolor="#ededed"><%=rs.getString("zone")%></td></tr>
<%
SNo++;
}
rs.close();
st.close();
con.close();
}
catch(Exception e){}
%>
</tbody>
<form action="" method="POST" name="frm_pages">
<table style="width: 100%;" align="center" border="0">
</table>
</body>
</html>
code of file meteridinfo.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%#page import="java.sql.*"%>
<%#page import="java.util.Date"%>
<%#page import="java.text.SimpleDateFormat"%>
<%
Connection con;
String sqlQuery="";
Statement st;
ResultSet rs=null;
%>
<html>
<head>
<title>Meterid Information
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" />
<style>
td{FONT: 13px Arial,sans-serif;}
th{FONT:bold 13px Arial,sans-serif;color:white;background-color:#3366ff}
input{FONT: 13px Arial,sans-serif;border: solid 1;}
select{font: 13px Arial,sans-serif}
#button{cursor:hand}
A:hover {COLOR: red}</style>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jquery.1.4.2.js"></script>
<script type="text/javascript" src="jsDatePick.jquery.min.1.3.js"></script>
<script type="text/javascript">
function calendarSetup() {pick("inputField1");pick("inputField2");} //initialize calendar on each date input field
function pick(inputField){new JsDatePick({useMode:2,target:inputField,dateFormat:"%d-%m-%Y"});} //display calendar for a given date input field
</script>
</head>
<body onload=calendarSetup()>
<body onload=calendarSetup()>
<form action="./meteridinfon.jsp" method="get" name="search">
<table width="500px;"align="center" border="0" cellpadding="4" cellspacing="3" bgcolor="#cccccc" bordercolor="#000000">
<tbody><tr>
<th colspan="3" align="middle"><strong>Meter ID Readings</strong></th></tr>
<tr><td>
<input type=hidden name="mid" value="<%=request.getParameter("mid")%>">
<label name="name" value="<%=request.getParameter("mid")%>"><font size="4">Meter ID : <%=request.getParameter("mid")%></font></label></td>
</tr>
<tr><td class="options1" colspan="3">
<font size="4">From</font>
<input type="text" size="20" maxlength="10" id="inputField1" name="fromDate">
<font size="4">To</font>
<input type="text" size="20" id="inputField2" name="toDate">
</font>
</td></tr>
<tr><td style="height: 30px;" colspan="4" align="center">
<input name="Search" value="Search" style= "HEIGHT:30px" style="width: 90px; border: 1px solid rgb(13, 31, 78);" type="submit">
</td></tr>
<%
try
{
int mid=Integer.parseInt(request.getParameter("mid"));
out.println("mid ===> +"+mid);
String fromDate=request.getParameter("fromDate");
String toDate=request.getParameter("toDate");
out.println("fromDate ===> +"+fromDate);
out.println("toDate ===> +"+toDate);
String query="select LastReading,Date,Time from Meter_List where Date between str_to_date('"+fromDate+"', '%Y-%m-%d') and str_to_date('"+toDate+"', '%Y-%m-%d') and Meterid="+mid;
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/suwatermeter","root","sumith");
st=con.createStatement();
if(fromDate !=null){
rs=st.executeQuery(query);
}
//ResultSet rs=st.executeQuery("select LastReading,Date,Time from Meter_List where Meterid="+meterid);
while(rs.next()){
%>
<table width="65%" align="center">
<tr bgcolor="lightblue">
<td>Reading</td>
<td bgcolor="lightblue"><%=rs.getInt("LastReading")%></td>
</tr>
<tr bgcolor="lightblue">
<td>Installation Date</td>
<td bgcolor="lightblue"><%=rs.getDate("Date")%></td>
</tr>
<tr bgcolor="lightblue">
<td>Inastallation Time</td>
<td bgcolor="lightblue"><%=rs.getTime("Time")%></td>
</tr>
<%
}
rs.close();
st.close();
con.close();
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</tbody>
</table>
</div>
</body>
</html>
In mysql table i have the date values as follows:
2012-05-10,
2012-03-04,
2012-03-04,
2012-09-12,
2012-09-12,
2012-09-12,
2012-09-12.
SELECT
*
FROM my_table
WHERE date(date_column1) >= DATE(NOW())
AND date(date_column2) <= DATE(NOW())
you can use
select * from my_table where date_coumn between '2012-05-01' AND '2012-05-11'
select LastReading,Date,Time from Meter_List
where str_to_date(date, '%Y-%m-%d')
between str_to_date('"+fromDate+"', '%Y-%m-%d') and
str_to_date('"+toDate+"', '%Y-%m-%d') and Meterid="+mid;