Mysql Connectivity Using Java Procedure

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 67

MYSQL CONNECTIVITY USING JAVA

Procedure

1. Open eclipse and create a workspace


2. Select the perspective as JAVA and create a new JAVA Project.
3. In the created project, right click and create a new class.
4. Import these library files:
* import java.sql.*;
5. For executing the JAVA application
* Right Click on JAVA Project and select Build path
* Select Configure build path and under library tab, add external JAR file (mysqlconnect5.16.jar)
and save the changes.

Location of SQL JAR FIles to be pasted before executing


c://eclipse/plugins

INSERT

package example;

import java.sql.*;

import java.util.Scanner;

public class Connectivity {

public static void main(String[] args) {

// TODO Auto-generated method stub

try

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

Scanner sc= new Scanner(System.in);

System.out.println("Enter Product ID");

int pid=sc.nextInt();

System.out.println("Enter Product Name");

String pname=sc.next();

System.out.println("Enter the Quantity");

int qty=sc.nextInt();

System.out.println("Enter the Price");

float price=sc.nextFloat();

System.out.println("Enter the Product entry date");


String edate=sc.next();

Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");

Statement s= c.createStatement();

s.executeUpdate("insert into inventory


values("+pid+",'"+pname+"',"+qty+","+price+",'"+edate+"')");

System.out.println("record inserted!!!");

catch(Exception e)

System.out.println("error in connection"+e);

Enter Product ID
102
Enter Product Name
Keyboard
Enter the Quantity
200
Enter the Price
5000
Enter the Product entry date
2018-11-25
record inserted!!!

SELECT ALL ROWS


package example;

import java.sql.*;

public class Select {


public static void main(String args[])
{
try
{
Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s= c.createStatement();
ResultSet rs=s.executeQuery("select * from inventory");
while(rs.next())
{
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));
System.out.println(rs.getString(5));
}

}
catch(Exception e)
{
System.out.println("error in connection"+e);
}

}
}

101
pencil
15
20
2018-09-11
102
Keyboard
200
5000
2018-11-25
103
Mouse
200
2500
2018-11-23

SELECT A PARTICULAR ROW

package example;
import java.util.Scanner;
import java.sql.*;

public class Select {


public static void main(String args[])
{
try
{
Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s= c.createStatement();
Scanner sc= new Scanner(System.in);
System.out.println("Enter Product ID");
int pid=sc.nextInt();
ResultSet rs=s.executeQuery("select * from inventory where
pid="+pid);
while(rs.next())
{
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));
System.out.println(rs.getString(5));
}

}
catch(Exception e)
{
System.out.println("error in connection"+e);
}

}
}

UPDATE

package example;

import java.sql.*;

import java.util.Scanner;

public class Update {

public static void main(String[] args) {

// TODO Auto-generated method stub

try

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

Scanner sc= new Scanner(System.in);

System.out.println("enter pid");

int pid=sc.nextInt();

System.out.println("enter the quantity");

int qty=sc.nextInt();

Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s= c.createStatement();

s.executeUpdate("update inventory set qty="+qty+" where pid="+pid);

System.out.println("record updated!!!");

catch(Exception e)

System.out.println("error in connection"+e);

enter pid
103
enter the quantity
210
record updated!!!

DELETE

package example;

import java.sql.*;

import java.util.Scanner;

public class Delete {

public static void main(String[] args) {

// TODO Auto-generated method stub

try

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

Scanner sc= new Scanner(System.in);

System.out.println("enter pid");

int pid=sc.nextInt();
Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");

Statement s= c.createStatement();

s.executeUpdate("delete from inventory where pid="+pid);

System.out.println("record deleted!!!");

catch(Exception e)

System.out.println("error in connection"+e);

enter pid
103
record deleted!!!
MYSQL CONNECTIVITY USING JAVA SERVLET

Procedure
1. Open eclipse and create a workspace
2. Select the perspective as J2EE and create a new Dynamic Web Project check the generate XML
option.
3. In the created project, right click and create a servlet.
4. Import these library files:
* import java.sql.*;
* import javax.servlet.*;
* import javax.servlet.http.*;
* import java.io.*;
Executing J2EE Application
right click the project -> BuildPath->Configure build path->Libraries->Add external JAR files
(mysqlconnect5.16.jar, servlet.api).

For APACHE TOMCAT


right click the project -> BuildPath->ProjectFacets->Runtimes->new->Apache Tomcat 7.0->finish-
>Apply->okay

Location of SQL JAR FIle and API to be pasted before executing


c://eclipse/plugins
c://apache/lib/servlet.api

INSERT

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Invent">
Product ID:<input type="text" name="pid"><br><br>
Product Name:<input type="text" name="pname"><br><br>
Quantity:<input type="text" name="qty"><br><br>
Price:<input type="text" name="price"><br><br>
Entry date:<input type="text" name="edate"><br><br>
<input type="submit" value="insert">
</form>
</body>
</html>

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

import java.io.*;
import java.sql.DriverManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class Invent
*/
@WebServlet("/Invent")
public class Invent extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* Default constructor.
*/
public Invent() {
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><body>");
int pid,qty;
float price;
String pname,edate;
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s=c.createStatement();
pid=Integer.parseInt(request.getParameter("pid"));
pname=request.getParameter("pname");
qty=Integer.parseInt(request.getParameter("qty"));
price=Float.parseFloat(request.getParameter("price"));
edate=request.getParameter("edate");
s.executeUpdate("insert into inventory
values("+pid+",'"+pname+"',"+qty+","+price+",'"+edate+"')");
out.println("Record inserted");
s.close();
c.close();
}
catch (Exception e)
{
System.out.println("Error in connection");
}
out.println("</body></html>");
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

SELECT ALL ROWS

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="select">
<input type="submit" value="select">
</form>
</body>
</html>

import javax.servlet.*;
import javax.servlet.http.*;

import java.sql.*;
import java.io.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class select
*/
@WebServlet("/select")
public class select extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public select() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><body>");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select * from inventory");
out.println("<table border=2><tr><td>Product
ID</td><td>Product Name</td>");
out.println("<td>Quantity</td><td>Price</td><td>Entry
Date</td></tr>");
while(rs.next())
{
out.println("<tr><td>");
out.println(rs.getString(1));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(2));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(3));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(4));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(5));
out.println("</td></tr>");
}
out.println("</table>");
}
catch (Exception e)
{
System.out.println("Error in connection");
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}
UPDATE

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Invent">
Product ID:<input type="text" name="pid"><br><br>
Quantity:<input type="text" name="qty"><br><br>
<input type="submit" value="Update">
</form>
</body>
</html>

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

import java.io.*;
import java.sql.DriverManager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class Invent
*/
@WebServlet("/Invent")
public class Invent extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* Default constructor.
*/
public Invent() {
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><body>");
int pid,qty;
float price;

try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s=c.createStatement();
pid=Integer.parseInt(request.getParameter("pid"));
qty=Integer.parseInt(request.getParameter("qty"));
s.executeUpdate("update inventory set qty="+qty+" where
pid="+pid);
out.println("Record updated");
s.close();
c.close();
}
catch (Exception e)
{
System.out.println("Error in connection");
}
out.println("</body></html>");
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}
DELETE

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Invent">
Product ID:<input type="text" name="pid"><br><br>
<input type="submit" value="Delete">
</form>
</body>
</html>

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

import java.io.*;
import java.sql.DriverManager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class Invent
*/
@WebServlet("/Invent")
public class Invent extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* Default constructor.
*/
public Invent() {
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><body>");
int pid,qty;

try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s=c.createStatement();
pid=Integer.parseInt(request.getParameter("pid"));
s.executeUpdate("delete from inventory where pid="+pid);
out.println("Record deleted");
s.close();
c.close();
}
catch (Exception e)
{
System.out.println("Error in connection");
}
out.println("</body></html>");
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}
SELECT

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="select">
Product ID:<input type="text" name="pid"><br><br>
<input type="submit" value="select">
</form>
</body>
</html>

import javax.servlet.*;
import javax.servlet.http.*;

import java.sql.*;
import java.io.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class select
*/
@WebServlet("/select")
public class select extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public select() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><body>");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s=c.createStatement();
int pid=Integer.parseInt(request.getParameter("pid"));
ResultSet rs=s.executeQuery("select * from inventory where
pid="+pid);
out.println("<table border=2><tr><td>Product
ID</td><td>Product Name</td>");
out.println("<td>Quantity</td><td>Price</td><td>Entry
Date</td></tr>");
while(rs.next())
{
out.println("<tr><td>");
out.println(rs.getString(1));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(2));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(3));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(4));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(5));
out.println("</td></tr>");
}
out.println("</table>");
}
catch (Exception e)
{
System.out.println("Error in connection");
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}
MYSQL CONNECTIVITY USING JSP

Procedure
1. Open eclipse and create a workspace
2. Select the perspective as J2EE and create a new Dynamic Web Project check the generate XML
option.
3. In the created project, right click and create a JSP.
4. Import these library files:
* <%@ page import= java.sql.*>
Executing JSP Application
right click the project -> BuildPath->Configure build path->Libraries->Add external JAR files
(mysqlconnect5.16.jar)

For APACHE TOMCAT


right click the project -> BuildPath->ProjectFacets->Runtimes->new->Apache Tomcat 7.0->finish-
>Apply->okay

Location of SQL JAR FIle and API to be pasted before executing


c://eclipse/plugins
c://apache/lib/servlet.api

INSERT
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="insert.jsp">
Product ID:<input type="text" name="pid"><br><br>
Product Name:<input type="text" name="pname"><br><br>
Quantity:<input type="text" name="qty"><br><br>
Price:<input type="text" name="price"><br><br>
Entry date:<input type="text" name="edate"><br><br>
<input type="submit" value="Insert">
</form>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s=c.createStatement();
int pid=Integer.parseInt(request.getParameter("pid"));
String pname= request.getParameter("pname");
int qty=Integer.parseInt(request.getParameter("qty"));
float price=Float.parseFloat(request.getParameter("price"));
String edate=request.getParameter("edate");
s.executeUpdate("insert into inventory
values("+pid+",'"+pname+"',"+qty+","+price+",'"+edate+"')");
out.println("Record inserted");
s.close();
c.close();
}
catch (Exception e)
{
System.out.println("Error in connection");
}
out.println("</body></html>");

%>
</body>
</html>
UPDATE

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s= c.createStatement();
pid=Integer.parseInt(request.getParameter("pid"));
qty=Integer.parseInt(request.getParameter("qty"));
s.executeUpdate("update inventory set qty="+qty+" where
pid="+pid);
out.println("Record updated");

}
catch(Exception e)
{
System.out.println(e);
}

%>
</body>
</html>
DELETE
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s= c.createStatement();
int pid=Integer.parseInt(request.getParameter("pid"));
String sql="delete from inventory where pid="+pid;
s.executeUpdate(sql);
out.println("record deleted");
}
catch(Exception e)
{
System.out.println(e);
}

%>
</body>
</html>
SELECT A PARTICULAR ROW

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select * from inventory where pid="+pid);
out.println("<table border=2><tr><td>Product ID</td><td>Product
Name</td>");
out.println("<td>Quantity</td><td>Price</td><td>Entry Date</td></tr>");
while(rs.next())
{
out.println("<tr><td>");
out.println(rs.getString(1));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(2));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(3));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(4));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(5));
out.println("</td></tr>");
}
out.println("</table>");
}
catch (Exception e)
{
System.out.println("Error in connection");
}

%>
</body>
</html>

SELECT ALL ROWS

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select * from inventory");
out.println("<table border=2><tr><td>Product ID</td><td>Product
Name</td>");
out.println("<td>Quantity</td><td>Price</td><td>Entry Date</td></tr>");
while(rs.next())
{
out.println("<tr><td>");
out.println(rs.getString(1));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(2));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(3));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(4));
out.println("</td>");
out.println("<td>");
out.println(rs.getString(5));
out.println("</td></tr>");
}
out.println("</table>");
}
catch (Exception e)
{
System.out.println("Error in connection");
}

%>
</body>
</html>
MYSQL CONNECTIVITY USING ASP.NET

Procedure:
1. Open Microsoft Visual Studio and create a new website.
2. In the website add new web form by right clicking the website and selecting add new item.
3. Design the website and write your script in .vb file
4. Import the following namespace
* imports System.Data
* imports System.Data.odbc
5. Creation of DNS
c://windows/SysWOW64/odbcad32 (double click)
Under User DSN
add -> Select MySQL ODBC 3.51 Driver -> Finish
Enter the following details
Datasource name (which is given in Connection string)
server : localhost
user: root
password: root
select the database
To check if the DSN is added
start -> Control panel ->Administrative Tools -> Datasource -> User DSN -> add ->

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb"


Inherits="Default2" %>

<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

Product ID:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
Product Name:&nbsp;
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
Quantity.
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
Price.
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<br />
<br />
Entry Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" Text="Insert" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" Text="Select All" />
&nbsp;&nbsp;
<asp:Button ID="Button3" runat="server" Text="Select" />
&nbsp;&nbsp;
<asp:Button ID="Button4" runat="server" Text="Update" />
&nbsp;
<asp:Button ID="Button5" runat="server" Text="Delete" />
<br />
<br />
<asp:DataGrid ID="DataGrid1" runat="server">
</asp:DataGrid>

</div>
</form>
</body>
</html>

Imports System.Data
Imports System.Data.Odbc

Partial Class Default2


Inherits System.Web.UI.Page
Dim c As OdbcConnection
Dim s As OdbcCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
c = New OdbcConnection("dsn=rajidsn;userid=root;password=;")
c.Open()

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)


Handles Button1.Click
s = New OdbcCommand("insert into inventory values(" & TextBox1.Text & ",'" &
TextBox2.Text & "'," & TextBox3.Text & "," & TextBox4.Text & ",'" & TextBox5.Text &
"')", c)
s.ExecuteNonQuery()
c.Close()
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)


Handles Button2.Click
Dim dbadapter As OdbcDataAdapter
Dim ds As New DataSet
dbadapter = New OdbcDataAdapter("select * from inventory", c)
dbadapter.Fill(ds, "t1")
DataGrid1.DataSource = ds.Tables("t1").DefaultView
DataGrid1.DataBind()
c.Close()
End Sub

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)


Handles Button3.Click
Dim dbadapter As OdbcDataAdapter
Dim ds As New DataSet
dbadapter = New OdbcDataAdapter("select * from inventory where pid=" &
TextBox1.Text, c)
dbadapter.Fill(ds, "t1")
DataGrid1.DataSource = ds.Tables("t1").DefaultView
DataGrid1.DataBind()
c.Close()

End Sub

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)


Handles Button4.Click
Dim up As String
up = "update inventory set qty=" & TextBox3.Text & " where pid=" & TextBox1.Text
s = New OdbcCommand(up, c)
s.ExecuteNonQuery()
c.Close()
End Sub

Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs)


Handles Button5.Click
s = New OdbcCommand("delete from inventory where pid=" & TextBox1.Text, c)
s.ExecuteNonQuery()
c.Close()

End Sub
End Class
MYSQL CONNECTIVITY USING VB

PROCEDURE
1. Open Visual basic 6.0 -> Standard EXE
2. Design the form.
3. Click Project tab -> select references -> Check Microsoft ActiveXDataObjects 2.0 Library and
click okay
4. For adding Data grid
5. Project -> components-> Microsoft DataGrid control 6.0 (OLEDB) and click okay.
6. Creation of DNS
c://windows/SysWOW64/odbcad32 (double click)
Under User DSN
add -> Select MySQL ODBC 3.51 Driver -> Finish
7. Enter the following details
Datasource name (which is given in Connection string)
server : localhost
user: root
password: root
select the database
To check if the DSN is added
start -> Control panel ->Administrative Tools -> Datasource -> User DSN -> add

Dim c As ADODB.Connection
Dim r As ADODB.Recordset
Private Sub Command1_Click()
Dim str As String
str = "insert into inventory values(" + Text1.Text + ",'" + Text2.Text + "'," + Text3.Text + ","
+ Text4.Text + ",'" + Text5.Text + "')"
r.Open str, c, adOpenDynamic, adLockOptimistic, a
MsgBox ("record inserted")
End Sub

Private Sub Command2_Click()


Dim str As String
str = "select * from inventory"
r.Open str, c, adOpenDynamic, adLockOptimistic, a
Set DataGrid1.DataSource = r.DataSource
End Sub
Private Sub Command3_Click()
Dim str As String
str = "update inventory set qty=" + Text3.Text + " where pid=" + Text1.Text
r.Open str, c, adOpenDynamic, adLockOptimistic, a
MsgBox ("record updated")
End Sub

Private Sub Command4_Click()


Dim str As String
str = "delete from inventory where pid=" + Text1.Text
r.Open str, c, adOpenDynamic, adLockOptimistic, a
MsgBox ("record deleted")
End Sub

Private Sub Command5_Click()


Dim str As String
str = "select * from inventory where pid=" + Text1.Text
r.Open str, c, adOpenDynamic, adLockOptimistic, a
Set DataGrid1.DataSource = r.DataSource
End Sub

Private Sub Form_Load()


Set c = New ADODB.Connection
c.ConnectionString = "dsn=rajidsn;uid=root;pwd=;"
c.Open
Set r = New ADODB.Recordset
r.CursorLocation = adUseClient
End Sub
MYSQL USING CONNECTIVITY PYTHON

Procedure
 copy pymysql folder from \\172.16.5.201\Msc_Lab\Staff\gavoury\mysql
 paste it in C:\Users\administrator\AppData\Local\Programs\Python\Python36\Lib

import pymysql

c=pymysql.connect(host='localhost',port=3306,user='root',passwd='',db='raji')

def insert():

pid=input("Enter product id")

pname=input("Enter product name")

qty=input("Enter the quantity")

price=input("Enter the price")

edate=input("Enter the entry date")

cur=c.cursor()

i_query="insert into inventory values(%s,%s,%s,%s,%s)"

rowcount=cur.execute(i_query,(pid,pname,qty,price,edate))

print("record inserted")

def update():

cur=c.cursor()

upid=input("Enter product id")

uqty=input("Enter the quantity")

u_query="update inventory set qty=%s where pid=%s"

rowcount1=cur.execute(u_query,(uqty,upid))

print("record updated")

def delete():

cur=c.cursor()

dpid=input("Enter product id")

d_query="delete from inventory where pid=%s"

rowcount2=cur.execute(d_query,(dpid))

print("record deleted")

def select():
cur=c.cursor()

s_query="select * from inventory"

cur.execute(s_query)

for row in cur:

print(row)

c.commit()

def sel():

cur=c.cursor()

spid=input("Enter product id")

s_query="select * from inventory where pid=%s"

cur.execute(s_query,(spid))

for row in cur:

print(row)

c.commit()

choice='y'

while choice=='y':

print("a.Insert b.Update c.Delete d.Select All e.Select")

ch=input("enter yout choice")

if ch=='a':

insert()

elif ch=='b':

update()

elif ch=='c':

delete()

elif ch=='d':

select()

elif ch=='e':

sel()

else:

print("enter a valid choice")

choice=input("Do you want to continue?(y/n)")


if choice!='y':

break

c.close()

a.Insert b.Update c.Delete d.Select All e.Select

enter yout choice a

Enter product id109

Enter product nameUSB

Enter the quantity200

Enter the price700

Enter the entry date2018-11-01

record inserted

Do you want to continue?(y/n)y

a.Insert b.Update c.Delete d.Select All e.Select

enter yout choice b

Enter product id109

Enter the quantity250

record updated

Do you want to continue?(y/n)y

a.Insert b.Update c.Delete d.Select All e.Select

enter yout choice e

Enter product id109

(109, 'USB', 250, 700.0, datetime.date(2018, 11, 1))

Do you want to continue?(y/n)y

a.Insert b.Update c.Delete d.Select All e.Select

enter yout choice d

(101, 'pencil', 15, 20.0, datetime.date(2018, 9, 11))

(102, 'Keyboard', 200, 5000.0, datetime.date(2018, 11, 25))

(103, 'pendrive', 300, 800.0, datetime.date(2018, 11, 26))

(104, 'mouse', 800, 3500.0, datetime.date(2018, 11, 28))


(109, 'USB', 250, 700.0, datetime.date(2018, 11, 1))

Do you want to continue?(y/n)y

a.Insert b.Update c.Delete d.Select All e.Select

enter yout choice c

Enter product id109

record deleted

Do you want to continue?(y/n)y

a.Insert b.Update c.Delete d.Select All e.Select

enter yout choice d

(101, 'pencil', 15, 20.0, datetime.date(2018, 9, 11))

(102, 'Keyboard', 200, 5000.0, datetime.date(2018, 11, 25))

(103, 'pendrive', 300, 800.0, datetime.date(2018, 11, 26))

(104, 'mouse', 800, 3500.0, datetime.date(2018, 11, 28))


MYSQL CONNECTIVITY USING BASH SHELL SCRIPT

[2msc17@moplabs ~]$ mysql -u root -p

Enter password:

mysql> create database raji;

ERROR 1007 (HY000): Can't create database 'raji'; database exists

mysql> use raji;

Database changed

mysql> create table inventory (pid int(3),pname varchar(25),qty int(4),price float(40),edate date);

Query OK, 0 rows affected (0.00 sec)

mysql> insert into inventory values(101,'pencil',15,20,'2018-11-26');

Query OK, 1 row affected (0.00 sec)

mysql> insert into inventory values(102,'keyboard',200,5000,'2018-11-27');

Query OK, 1 row affected (0.00 sec)

mysql> select * from inventory;

+------+-----------+------+-------+------------+

| pid | pname | qty | price | edate |

+------+-----------+------+-------+------------+

| 101 | pencil | 15 | 20 | 2018-11-26 |

| 102 | keyboard | 200 | 5000 | 2018-11-27 |

| 103 | pendrive | 800 | 5000 | 2018-11-28 |

| 104 | mouse | 800 | 3000 | 2018-11-29 |

| 105 | hard disk | 300 | 7000 | 2018-11-29 |

+------+-----------+------+-------+------------+

5 rows in set (0.00 sec)


Program:

echo "1.Insert 2.Update 3.Delete 4.Select 5.Select All"

read -p "Enter your choice:" ch

case $ch in

1)mysql -u root -p mop<<EOF

use raji;

insert into inventory values(106,'USB',300,7000,'2018-11-29');

select * from inventory;

EOF

echo "record inserted"

;;

2)mysql -u root -p mop<<EOF

use raji;

update inventory set qty=350 where pid=106;

select * from inventory;

EOF

echo "record updated"

;;

3)mysql -u root -p mop<<EOF

use raji;

delete from inventory where pid=106;

select * from inventory;

EOF

echo "record deleted"

;;

4)mysql -u root -p mop<<EOF

use raji;

select * from inventory where pid=103;

EOF

;;
5)mysql -u root -p mop<<EOF

use raji;

select * from inventory;

EOF

;;

esac

"swsql" 39L, 685C written

[2msc17@moplabs ~]$ sh swsql

1.Insert 2.Update 3.Delete 4.Select 5.Select All

Enter your choice:1

Enter password:

pid pname qty price edate

101 pencil 15 20 2018-11-26

102 keyboard 200 5000 2018-11-27

103 pendrive 800 5000 2018-11-28

104 mouse 800 3000 2018-11-29

105 hard disk 300 7000 2018-11-29

106 USB 300 7000 2018-11-29

106 USB 300 7000 2018-11-29

record inserted

[2msc17@moplabs ~]$ sh swsql

1.Insert 2.Update 3.Delete 4.Select 5.Select All

Enter your choice:2

Enter password:

pid pname qty price edate

101 pencil 15 20 2018-11-26

102 keyboard 200 5000 2018-11-27

103 pendrive 800 5000 2018-11-28


104 mouse 800 3000 2018-11-29

105 hard disk 300 7000 2018-11-29

106 USB 350 7000 2018-11-29

106 USB 350 7000 2018-11-29

record updated

[2msc17@moplabs ~]$ sh swsql

1.Insert 2.Update 3.Delete 4.Select 5.Select All

Enter your choice:3

Enter password:

pid pname qty price edate

101 pencil 15 20 2018-11-26

102 keyboard 200 5000 2018-11-27

103 pendrive 800 5000 2018-11-28

104 mouse 800 3000 2018-11-29

105 hard disk 300 7000 2018-11-29

record deleted

[2msc17@moplabs ~]$ sh swsql

1.Insert 2.Update 3.Delete 4.Select 5.Select All

Enter your choice:4

Enter password:

pid pname qty price edate

103 pendrive 800 5000 2018-11-28

[2msc17@moplabs ~]$ sh swsql

1.Insert 2.Update 3.Delete 4.Select 5.Select All

Enter your choice:5

Enter password:

pid pname qty price edate

101 pencil 15 20 2018-11-26

102 keyboard 200 5000 2018-11-27

103 pendrive 800 5000 2018-11-28

104 mouse 800 3000 2018-11-29


105 hard disk 300 7000 2018-11-29

[2msc17@moplabs ~]$
MYSQL CONNECTIVITY USING C

Procedure:

1. Type the program in notepad


2. Copy mysql++-3.0.9 from \\172.16.5.201\Msc_Lab\Staff\gavoury\j2ee
3. Paste mysql++-3.0.9 to C:\
4. Copy mysql-noinstall-5.1.42-win32(zip file) from \\172.16.5.201\Msc_Lab
5. Paste that file in C:\ProgramFile(X86)\MySQL and extract there
6. Open visual studio C++ 6.0 and open the cpp file
7. compile the project (Build -> compile)
8. Tools->customize->directories and add C:\mysql++-3.0.9\lib and C:\Program Files
(x86)\MySQL\mysql-5.1.42-win32\include
9. select the project and goto Project->settings
a. goto c/c++ tab
1. select category code generation and choose pentium as proccessor and
multithreaded DLL as run time library
2. select category pre compiled headers and select 1st option no
precomplied processors
3 select category preprocessors and add C:\Program Files
(x86)\MySQL\mysql-5.1.42-win32\include to include libraries
b. goto link tab
1. In object/library modules add wsock32.lib regex.lib zlib.lib mysys.lib
libmysql.lib strings.lib
2. In Additional library path add C:\Program Files
(x86)\MySQL\mysql-5.1.42-win32\lib\opt
10. build the project and execute it.

INSERT

#include<winsock2.h>

#include<mysql.h>

#include<stdio.h>

#include<conio.h>

#include<string.h>

MYSQL *c,mysql;

MYSQL_RES *r;

MYSQL_ROW_row;

int q;

char query[100]="";

void main()

{
int pid,qty;

float price;

char pid1[3],qty1[2];

char pname[25],edate[30],price1[40];

mysql_init(&mysql);

c=mysql_real_connect(&mysql,"localhost","root","","raji",0,0,0);

printf("Enter Product ID\n");

scanf("%d",&pid);

printf("Enter Product Name\n");

scanf("%s",pname);

printf("Enter the quantity\n");

scanf("%d",&qty);

printf("Enter the price\n");

scanf("%f",&price);

printf("enter the entry date\n");

scanf("%s",edate);

itoa(pid,pid1,10);//10 is for decimal, 16 for hexadecimal

itoa(qty,qty1,10);

sprintf(price1,"%f",price);

strcat(query,"insert into inventory values(");

strcat(query,pid1);

strcat(query,",'");

strcat(query,pname);

strcat(query,"',");

strcat(query,qty1);

strcat(query,",");

strcat(query,price1);

strcat(query,",'");

strcat(query,edate);

strcat(query,"')");

q=mysql_query(c,query);
printf("\n Record inserted");

SELECT ALL ROWS

#include<winsock2.h>

#include<mysql.h>

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<string.h>

MYSQL *c,mysql;

MYSQL_RES *r;

MYSQL_ROW row;

int q;

char query[100]="";

void main()

{
mysql_init(&mysql);

c=mysql_real_connect(&mysql,"localhost","root","","raji",0,0,0);

strcat(query,"select * from inventory");

q=mysql_query(c,query);

r=mysql_store_result(c);

printf("Product details\n");

while((row=mysql_fetch_row(r))!= NULL)

printf(row[0]);

printf("\n");

printf(row[1]);

printf("\n");

printf(row[2]);

printf("\n");

printf(row[3]);

printf("\n");

printf(row[4]);

}
UPDATE

#include<winsock2.h>

#include<mysql.h>

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<string.h>

MYSQL *c,mysql;

MYSQL_RES *r;

MYSQL_ROW _row;

int q;

char query[100]="";

void main()

int pid,qty;

char pid1[3],qty1[2];

mysql_init(&mysql);

c=mysql_real_connect(&mysql,"localhost","root","","raji",0,0,0);

printf("Enter Product ID\n");

scanf("%d",&pid);

printf("Enter the quantity\n");

scanf("%d",&qty);

itoa(pid,pid1,10);//10 is for decimal, 16 for hexadecimal

itoa(qty,qty1,10);

strcat(query,"update inventory set qty=");

strcat(query,qty1);

strcat(query," where pid=");

strcat(query,pid1);

printf("record updated\n");

q=mysql_query(c,query);
}

DELETE

#include<winsock2.h>

#include<mysql.h>

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<string.h>

MYSQL *c,mysql;

MYSQL_RES *r;

MYSQL_ROW _row;

int q;

char query[100]="";

void main()

int pid;
char pid1[3];

mysql_init(&mysql);

c=mysql_real_connect(&mysql,"localhost","root","","raji",0,0,0);

printf("Enter Product ID\n");

scanf("%d",&pid);

itoa(pid,pid1,10);//10 is for decimal, 16 for hexadecimal

strcat(query,"delete from inventory where pid=");

strcat(query,pid1);

q=mysql_query(c,query);

printf("record deleted\n");

SELECT A PARTICULAR ROW

#include<winsock2.h>

#include<mysql.h>

#include<iostream.h>
#include<conio.h>

#include<stdio.h>

#include<string.h>

MYSQL *c,mysql;

MYSQL_RES *r;

MYSQL_ROW row;

int q,pid;

char pid1[3];

char query[100]="";

void main()

mysql_init(&mysql);

c=mysql_real_connect(&mysql,"localhost","root","","raji",0,0,0);

printf("Enter Product ID\n");

scanf("%d",&pid);

itoa(pid,pid1,10);

strcat(query,"select * from inventory where pid=");

strcat(query,pid1);

q=mysql_query(c,query);

r=mysql_store_result(c);

printf("Product details\n");

while((row=mysql_fetch_row(r))!= NULL)

printf(row[0]);

printf("\n");

printf(row[1]);

printf("\n");

printf(row[2]);

printf("\n");

printf(row[3]);

printf("\n");
printf(row[4]);

}
MYSQL CONNECTIVITY USING C++

Procedure

1. Type the program in notepad


2. Copy mysql++-3.0.9 from \\172.16.5.201\Msc_Lab\Staff\gavoury\j2ee
3. Paste mysql++-3.0.9 to C:\
4. Copy mysql-noinstall-5.1.42-win32(zip file) from \\172.16.5.201\Msc_Lab
5. Paste that file in C:\ProgramFile(X86)\MySQL and extract there
6. Open visual studio C++ 6.0 and open the cpp file
7. compile the project (Build -> compile)
8. Tools->customize->directories and add C:\mysql++-3.0.9\lib and C:\Program Files
(x86)\MySQL\mysql-5.1.42-win32\include
9. select the project and goto Project->settings
a. goto c/c++ tab
1. select category code generation and choose pentium as proccessor and
multithreaded DLL as run time library
2. select category pre compiled headers and select 1st option no
precomplied processors
3 select category preprocessors and add C:\Program Files
(x86)\MySQL\mysql-5.1.42-win32\include to include libraries
b. goto link tab
1. In object/library modules add wsock32.lib regex.lib zlib.lib mysys.lib
libmysql.lib strings.lib
2. In Additional library path add C:\Program Files
(x86)\MySQL\mysql-5.1.42-win32\lib\opt
10. build the project and execute it.

INSERT

#include<winsock2.h>

#include<mysql.h>

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<string.h>

MYSQL *c,mysql;

MYSQL_RES *r;

MYSQL_ROW _row;

int q;

char query[100]="";
void main()

int pid,qty;

float price;

char pid1[3],qty1[2];

char pname[25],edate[30],price1[40];

mysql_init(&mysql);

c=mysql_real_connect(&mysql,"localhost","root","","raji",0,0,0);

cout<<"Enter Product ID"<<endl;

cin>>pid;

cout<<"Enter Product Name"<<endl;

cin>>pname;

cout<<"enter the quantity"<<endl;

cin>>qty;

cout<<"enter the price"<<endl;

cin>>price;

cout<<"enter the entry date"<<endl;

cin>>edate;

itoa(pid,pid1,10);//10 is for decimal, 16 for hexadecimal

itoa(qty,qty1,10);

sprintf(price1,"%f",price);

strcat(query,"insert into inventory values(");

strcat(query,pid1);

strcat(query,",'");

strcat(query,pname);

strcat(query,"',");

strcat(query,qty1);

strcat(query,",");

strcat(query,price1);

strcat(query,",'");

strcat(query,edate);
strcat(query,"')");

q=mysql_query(c,query);

SELECT ALL

#include<winsock2.h>

#include<mysql.h>

#include<iostream.h>

#include<conio.h>

#include<string.h>

MYSQL *c,mysql;

MYSQL_RES *r;

MYSQL_ROW row;

int q;

char query[100]="";

void main()

mysql_init(&mysql);
c=mysql_real_connect(&mysql,"localhost","root","","raji",0,0,0);

strcat(query,"select * from inventory");

q=mysql_query(c,query);

r=mysql_store_result(c);

cout<<"product details"<<endl;

while((row=mysql_fetch_row(r))!= NULL)

cout<<row[0]<<endl;

cout<<row[1]<<endl;

cout<<row[2]<<endl;

cout<<row[3]<<endl;

cout<<row[4]<<endl;

UPDATE

#include<winsock2.h>

#include<mysql.h>
#include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<string.h>

MYSQL *c,mysql;

MYSQL_RES *r;

MYSQL_ROW _row;

int q;

char query[100]="";

void main()

int pid,qty;

char pid1[3],qty1[2];

mysql_init(&mysql);

c=mysql_real_connect(&mysql,"localhost","root","","raji",0,0,0);

cout<<"Enter Product ID"<<endl;

cin>>pid;

cout<<"Enter the quantity"<<endl;

cin>>qty;

itoa(pid,pid1,10);//10 is for decimal, 16 for hexadecimal

itoa(qty,qty1,10);

strcat(query,"update inventory set qty=");

strcat(query,qty1);

strcat(query," where pid=");

strcat(query,pid1);

cout<<"record updated"<<endl;

q=mysql_query(c,query);

}
DELETE

#include<winsock2.h>

#include<mysql.h>

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<string.h>

MYSQL *c,mysql;

MYSQL_RES *r;

MYSQL_ROW _row;

int q;

char query[100]="";

void main()

int pid;

char pid1[3];

mysql_init(&mysql);
c=mysql_real_connect(&mysql,"localhost","root","","raji",0,0,0);

cout<<"Enter Product ID"<<endl;

cin>>pid;

itoa(pid,pid1,10);//10 is for decimal, 16 for hexadecimal

strcat(query,"delete from inventory where pid=");

strcat(query,pid1);

q=mysql_query(c,query);

cout<<"record deleted"<<endl;

}
MYSQL CONNECTIVITY USING PHP

INSERT

<html>

<body>

<form action="save.php" method="post">

Product ID:<input type="text" name="pid"><br><br>

Product Name:<input type="text" name="pname"><br><br>

Quantity:<input type="text" name="qty"><br><br>

Price:<input type="text" name="price"><br><br>

Entry date:<input type="text" name="edate"><br><br>

<input type="submit" value="insert">

</form>

</body>

</html>

<?php

$con= mysql_connect("localhost","root","");

mysql_select_db("raji",$con);

$pid=$_POST["pid"];

$pname=$_POST["pname"];

$qty=$_POST["qty"];

$price=$_POST["price"];

$edate=$_POST["edate"];

$query=mysql_query("insert into inventory values


(".$pid.",'".$pname."',".$qty.",".$price.",'".$edate."');");

echo "record inserted";

?>
UPDATE

<html>

<body>

<form method="post" action="update.php">

Product ID:<input type="text" name="pid"><br><br>

Quantity:<input type="text" name="qty"><br><br>


<input type="submit" value="update">

</form>

</body>

</html>

<?php

$con= mysql_connect("localhost","root","");

mysql_select_db("raji",$con);

$pid=$_POST["pid"];

$qty=$_POST["qty"];

$query=mysql_query("update inventory set qty=".$qty." where pid=".$pid.";");

echo "record updated";

?>
DELETE

<html>

<body>

<form method="post" action="del.php">

Product ID:<input type="text" name="pid"><br><br>

<input type="submit" value="delete">

</form>

</body>

</html>

<?php

$con= mysql_connect("localhost","root","");

mysql_select_db("raji",$con);

$pid=$_POST["pid"];

$query=mysql_query("delete from inventory where pid=".$pid.";");

echo "record deleted";

?>
SELECT ALL

<html>

<body>

<form method="post" action="sel.php">

<input type="submit" value="select">

</form>

</body>

</html>

<?php
$con=mysql_connect("localhost","root","");

mysql_select_db("raji",$con);

$b=$_POST["submit"];

if ($b = "submit")

$rs=mysql_query("select * from inventory");

while ($q=mysql_fetch_row($rs))

echo $q[0]." ";

echo $q[1]." ";

echo $q[2]." ";

echo $q[3]." ";

echo $q[4];

echo "<br>";

You might also like