Have successfully inserted the values but, how to insert with autoincrement? - mysql

My database: MYSQL SCREENSHOT
I have inserted the values from HTML to the MySQL database. How can I use the insert command for autoincrement column?
Servlet code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.sql.*;
#WebServlet(name = "Register")
public class Register extends HttpServlet {
static String username="root";
static String password="root";
static String dburl= "jdbc:mysql://localhost:3306/conferencesystem";
static String mydriver = "com.mysql.cj.jdbc.Driver";
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String Firstname = request.getParameter("firstname");
String Lastname = request.getParameter("lastname");
int Mobilenumber =
Integer.parseInt(request.getParameter("mobilenumber"));
String Email = request.getParameter("emailid");
String Pass = request.getParameter("password");
out.println("<html>");
out.println("<body>");
out.println("<h3>Guest Details </h3>");
out.println("" + Firstname);
out.println("" + Lastname);
out.println("" + Email);
out.println("</body>");
out.println("</html>");
int id = 1101;
Connection con = null;
try {
Class.forName(mydriver);
con = DriverManager.getConnection(dburl, username, password);
String query = "INSERT INTO author values(?,?,?,?,?,?)";
PreparedStatement stmt = con.prepareStatement(query);
stmt.setInt(1,id);
stmt.setString(2,Firstname);
stmt.setString(3,Lastname);
stmt.setInt(4,Mobilenumber);
stmt.setString(5,Email);
stmt.setString(6,Pass);
out.println("Your Record has been successfully inserted");
int res= stmt.executeUpdate();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
h3{
font-family: Calibri;
font-size: 25pt;
font-style: normal;
font-weight: bold;
color:SlateBlue;
text-align: center;
text-decoration: underline
}
table{
font-family: Calibri;
color:white;
font-size: 11pt;
font-style: normal;
font-weight: bold;
text-align:center;
background-color: SlateBlue;
border-collapse: collapse;
border: 2px solid navy
}
table.inner{
border: 0px
}
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<html>
<head>
<title> Author Registration Form </title>
</head>
<link rel="stylesheet" href="styles.css">
<body>
<form method="post" action="http://localhost:8080/Register">
<h3>AUTHOR REGISTRATION FORM</h3>
<table align="center" cellpadding = "10">
<!----- First Name ---------------------------------------------------------->
<tr>
<td>FIRST NAME</td>
<td><input type="text" name="firstname" maxlength="30"/>
(max 30 characters a-z and A-Z)
</td>
</tr>
<!----- Last Name ---------------------------------------------------------->
<tr>
<td>LAST NAME</td>
<td><input type="text" name="lastname" maxlength="30"/>
(max 30 characters a-z and A-Z)
</td>
</tr>
<!----- Mobile Number ---------------------------------------------------------->
<tr>
<td>MOBILE NUMBER</td>
<td>
<input type="text" name="mobilenumber" maxlength="10" />
(10 digit number)
</td>
</tr>
<!----- Email Id ---------------------------------------------------------->
<tr>
<td>EMAIL ID</td>
<td><input type="text" name="emailid" maxlength="100" /></td>
</tr>
<!----- Choose password ---------------------------------------------------------->
<tr>
<td>PASSWORD</td>
<td><input type="password" name="password" maxlength="100" /></td>
</tr>
<!----- Submit and Reset ------------------------------------------------->
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</body>
</html>
I'm trying to insert data from the form data, but it doesn't work. How can I fix it?
In this updated question, I have successfully fixed some problems in inserting the values, but how can I deal with the autoincrementing column?

INSERT INTO author
(firstname
,lastname
,mobilenumber
,email
, pass) values(?,?,?,?,?);
And remove id from the prepared strings

Related

How to connect to phpmyadmin localhost database from microsoft web expression 4

How to connect to the database it keeps saying
Fatal error: Uncaught Error: Class "msqli" not found in C:\xampp\htdocs\5Dec2021\Order.php:90 Stack trace: #0 {main} thrown in C:\xampp\htdocs\5Dec2021\Order.php on line 90
It works fine when I go to the http://localhost/5Dec2021/Menu.html I can click on the buttons and answer the textboxes Herebut after i submit it become like This
THIS IS MY HTML
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<form method="post" action="Order.php">
<table border="1" style="width: 100%">
<tr>
<th colspan="2" style="height: 25px">Pizza Shop 2.0</th>
</tr>
<tr>
<td style="width: 310px">Name:</td>
<td>
<input name="Text1" id="Name" type="text" style="width: 299px" /></td>
</tr>
<tr>
<td style="width: 310px">Pizza Topping:</td>
<td><input name="Checkbox1[]" type="checkbox" id="supreme"value="Supreme" />Supreme<br>
<input name="Checkbox1[]" type="checkbox" id="vegetarian" value="Vegetarian" />Vegetarian<br>
<input name="Checkbox1[]" type="checkbox" id="haiwaian" value="Haiwaian" />Haiwaian
</td>
</tr>
<tr>
<td style="width: 310px">Pizza Sauce:</td>
<td><select name="Select1" id="dropdown" style="width: 296px">
<option selected="selected" value="0">-</option>
<option value="Ketchup">Ketchup</option>
<option value="Bolognese">Bolognese</option>
<option value="CheeseSpread">Cheese Spread</option>
</select></td>
</tr>
<tr>
<td style="height: 23px; width: 310px;">Optional Extra:</td>
<td style="height: 23px">
<input name="Checkbox2[]" type="checkbox" id="extra" value="Extra cheese" />Extra Cheese <br>
<input name="Checkbox2[]" type="checkbox" id="gluten" value="Gluten free base" />Gluten Free Base
</td>
</tr>
<tr>
<td style="width: 310px" colspan="2">Delivery Instruction:<br>
<textarea name="TextArea1" style="width: 608px; height: 127px"></textarea></td>
</tr>
<tr>
<td style="width: 310px" colspan="2"><input name="submit" type="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>
</html>
THIS IS MY PHP
<?php
//variable declaration
$name=$_POST['Text1'];
$p=0;
$p2=0;
if (isset($_POST['Checkbox1']))
{
$top=$_POST['Checkbox1'];
$c=count($top);
for ($i=0; $i<$c;$i++)
{
If($top[$i]=="Supreme")
{
$p=$p+15;
}
If($top[$i]=="Vegetarian")
{
$p=$p+11;
}
If($top[$i]=="Haiwaian")
{
$p=$p+12;
}
}
}
if (isset($_POST['Select1']))
{
$sauce=$_POST['Select1'];
If($sauce=="0")
{
$p2=$p2+0;
}
If($sauce=="Ketchup")
{
$p2=$p2+4;
}
If($sauce=="Bolognese")
{
$p2=$p2+3;
}
If($sauce=="CheeseSpread")
{
$p2=$p2+5;
}
}
$p3=0;
if (isset($_POST['Checkbox2']))
{
$extra=$_POST['Checkbox2'];
$c=count($extra);
for ($i=0; $i<$c; $i++)
{
If($extra[$i]=="Extra cheese")
{
$p3=$p3+10;
}
If($extra[$i]=="Gluten free base")
{
$p3=$p3+5;
}
}
}
$delivery =$_POST['TextArea1'];
$total=0;
$total=$p+$p2+$p3;
$top=implode(" ",$_POST['Checkbox1']); // HAVE TO IMPLODE IF CAN BE MULTIPLE VALUES.
$extra=implode(" ",$_POST['Checkbox2']);
date_default_timezone_set("Asia/Kuala_Lumpur");
$date=date("d-m-Y H:i:sa");
echo "<h1>Billing statement</h1>";
echo "<br>";
echo "Hi ".$name;
echo "<br>";
echo "Total bill RM: ".$total;
//database configuration (pizzatime is the folder of the table name)
$con= new msqli("localhost","root","","pizzatime");
//is the connection working? connection error
if($con->connect_error)
{
die("Warning!Connection Failed!".$con->connect_error);
}
//if connection is ok (orderpizza is the table name, and INSERT INTO IS THE COLUMN NAMES WHILE THE VALUES ARE THE CONTAINERS OF THE BUTTONS/CHECKBOX/...
$database="INSERT INTO orderpizza(Time,Name,Top,Sauce,Extra,Delivery,Total) VALUES
('$date','$name','$top','$sauce','$extra','$delivery','$total')";
if($con->query($database)===TRUE)
{
echo "<br>";
echo "<alert>'Successfully save into the database'</alert>;";
}
else
{
echo "Error".$con->connect_error;
}
$con->close();
?>
This is database I created in localhost phpmyadmin
I had to change my Xampp port to 4306 because it wasn't working so I have to add :4306 next to the localhost
//database configuration (pizzatime is the folder of the table name)
$con = new msqli("localhost**:4306**","root","","pizzatime");

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 + "'");

pass a parameter into named query

I have the following query in my model(Supplier) class :
#NamedQuery(name = "Supplier.findSupplierKeyId", query = "SELECT s FROM Supplier s WHERE s.supplierid LIKE (':supplieridkey%')")
I have following function in my Controller(SupplierSerivce) class:
public List<Supplier> findSupplierKeyId(String supplierkeyid){
List<Supplier> supplierList = mgr.createNamedQuery("Supplier.findSupplierKeyId").setParameter("supplieridkey", supplierkeyid).getResultList();
return supplierList;
}
I want to get in a html textfield :
<form action="SearchSupplierIdKey.jsp" method="POST">
<div>
<input type="text" name="supIdKey"/>
<input type="submit" value="Search" name="button"/>
</div>
</form>
then get parameter from the textfield and pass it into supService.findSupplierKeyId through servlet:
public class SearchSupplierIdKey extends HttpServlet {
#PersistenceContext
EntityManager em;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
SupplierService supService = new SupplierService(em);
HttpSession session = request.getSession();
String supId = (String) session.getAttribute("supId");
String button = (String) session.getAttribute("button");
List<Supplier> supplierListResult = supService.findSupplierKeyId(supId);
session.setAttribute("supplierListResult", supplierListResult);
if (button.equals("Search")) {
response.sendRedirect("ViewSupplierByIdKey.jsp");
}
} catch (Exception ex) {
Logger.getLogger(AddSupplier.class.getName()).log(Level.SEVERE, null, ex);
}
}
Then show the result in ViewSupplierByIdKey.jsp :
<%#page import="java.util.List"%>
<%#page import="model.Supplier"%>
<!-- retrieve session object, itemList -->
<%
List<Supplier> supplierListResult = (List)session.getAttribute("supplierListResult");
%>
<html>
<head>
<title>Supplier Search Result</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<table cellspacing="0" cellpadding="0" style="margin-left:auto; margin-right:auto; border:solid; width: 1000px">
<tr style="border:solid">
<td style="border:solid ">
<h3 style="text-align: center">ABC Health Supplement Shop System</h3>
</td>
</tr>
<tr style="border: solid">
<td style="border: solid">
<center><h1><i><b><font face="Segoe Script" color="#FF0000">Supplier Search Result(By ID Key)</font></b></i></h1></center>
</td>
</tr>
<tr style="border:solid">
<td style="border:solid">
<center><div>
<table border="1">
<tr>
<th>Supplier ID</th>
<th>Supplier Name</th>
<th>Manufacturer</th>
<th>Contact Num</th>
<th>Address</th>
</tr>
<% for (Supplier supplier: supplierListResult){ %>
<tr>
<td><%= supplier.getSupplierid() %></td>
<td><%= supplier.getSuppliername()%> </td>
<td><%= supplier.getManufacturer()%> </td>
<td><%= supplier.getContactnum()%> </td>
<td><%= supplier.getAddress()%> </td>
</tr>
<% } %>
</table>
<br><br>
<p>Back to Menu page</p>
</div>
</center>
</td>
</tr>
</table>
</body>
</html>
but i dont knw why i cant proceed to ViewSupplierByIdKey.jsp, it stuck at the controller class
(SearchSupplierIdKey.java). Please Help :( :(
One thing that I notice is the request parameter is retrieved using the name supId:
String supId = (String) session.getAttribute("supId");
but specified as supIdKey in the HTML:
<input type="text" name="supIdKey"/>
The name attribute used on the input should match the key being used to retrieve the attribute.

Unable to use mailto function of email to send form data [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a form and I want to send its data to my email ID using mailto function email of HTML. however this is not working for me. please suggest me the best way to do this using HTML.
Below is my code.
<html>
<head>
<title>
Contact us
</title>
<style>
h1
{
margin-top:30px;
text-align:center;
}
td
{
font-weight:bold;
}
</style>
</head>
<body bgcolor="#cococo">
<h1>
Call us at
<p>
995-3100-995
</h1>
<div style="text-align:center;"><img src="phone.jpg"/></div>
<p><p><p><p>
<h1>Let us contact you..</h1>
<form action"mailto:luthra.vaibhav#gmail.com" method="post" enctype="text/plain">
<fieldset>
<legend style="text-align:center;"><h2>Your contact details</h2></legend>
<table style="margin-left:40%">
<tr>
<td>Name</td>
<td><input type="text"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text"></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="submit" value="Contact Me" align="right"></td>
<td><input type="reset" value="Clear All"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
Try Using PHP Instead. MAILTO tag is only a link.
File index.html :
<html>
<head>
<title>
Contact us
</title>
<style>
h1
{
margin-top:30px;
text-align:center;
}
td
{
font-weight:bold;
}
</style>
</head>
<body bgcolor="#cococo">
<h1>
Call us at
<p>
995-3100-995
</h1>
<div style="text-align:center;"><img src="phone.jpg"/></div>
<p><p><p><p>
<h1>Let us contact you..</h1>
<form action="email.php" method="post" enctype="text/plain">
<fieldset>
<legend style="text-align:center;"><h2>Your contact details</h2></legend>
<table style="margin-left:40%">
<tr>
<td>Name</td>
<td><input type="text" name="data"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text" name="contact"></td>
</tr>
<tr>
<td><input type="submit" value="Contact Me" align="right"></td>
<td><input type="reset" value="Clear All"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
File email.php :
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email));
}
if($_POST) {
$emailTo = 'email#gmail.com';
$data = addslashes(trim($_POST['email']));
if(!$data) {
$array = array();
$array['valid'] = 0;
$array['message'] = 'Insert a valid data!';
echo json_encode($array);
}
else {
$subject = 'Header';
$body = "BODY";
// uncomment this to set the From and Reply-To emails, then pass the $headers variable to the "mail" function below
// $headers = "From: ".$user_token." <" . $user_token . ">" . "\r\n" . "Reply-To: " . $user_token;
mail($emailTo, $subject, $body);
}
}
you're missing the equal sign
<form action="mailto:luthra.vaibhav#gmail.com"
method="post" enctype="text/plain">

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;