Mysql Connectivity Using Java Procedure
Mysql Connectivity Using Java Procedure
Mysql Connectivity Using Java Procedure
Procedure
INSERT
package example;
import java.sql.*;
import java.util.Scanner;
try
Class.forName("com.mysql.jdbc.Driver");
int pid=sc.nextInt();
String pname=sc.next();
int qty=sc.nextInt();
float price=sc.nextFloat();
Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s= c.createStatement();
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!!!
import java.sql.*;
}
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
package example;
import java.util.Scanner;
import java.sql.*;
}
catch(Exception e)
{
System.out.println("error in connection"+e);
}
}
}
UPDATE
package example;
import java.sql.*;
import java.util.Scanner;
try
Class.forName("com.mysql.jdbc.Driver");
System.out.println("enter pid");
int pid=sc.nextInt();
int qty=sc.nextInt();
Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s= c.createStatement();
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;
try
Class.forName("com.mysql.jdbc.Driver");
System.out.println("enter pid");
int pid=sc.nextInt();
Connection c=
DriverManager.getConnection("jdbc:mysql://localhost:3306/raji","root","");
Statement s= c.createStatement();
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).
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
}
<!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)
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>
%>
</body>
</html>
UPDATE
}
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
%>
</body>
</html>
%>
</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 ->
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Product ID:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
Product Name:
<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:
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Insert" />
<asp:Button ID="Button2" runat="server" Text="Select All" />
<asp:Button ID="Button3" runat="server" Text="Select" />
<asp:Button ID="Button4" runat="server" Text="Update" />
<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
End Sub
End Sub
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
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():
cur=c.cursor()
rowcount=cur.execute(i_query,(pid,pname,qty,price,edate))
print("record inserted")
def update():
cur=c.cursor()
rowcount1=cur.execute(u_query,(uqty,upid))
print("record updated")
def delete():
cur=c.cursor()
rowcount2=cur.execute(d_query,(dpid))
print("record deleted")
def select():
cur=c.cursor()
cur.execute(s_query)
print(row)
c.commit()
def sel():
cur=c.cursor()
cur.execute(s_query,(spid))
print(row)
c.commit()
choice='y'
while choice=='y':
if ch=='a':
insert()
elif ch=='b':
update()
elif ch=='c':
delete()
elif ch=='d':
select()
elif ch=='e':
sel()
else:
break
c.close()
record inserted
record updated
record deleted
Enter password:
Database changed
mysql> create table inventory (pid int(3),pname varchar(25),qty int(4),price float(40),edate date);
+------+-----------+------+-------+------------+
+------+-----------+------+-------+------------+
+------+-----------+------+-------+------------+
case $ch in
use raji;
EOF
;;
use raji;
EOF
;;
use raji;
EOF
;;
use raji;
EOF
;;
5)mysql -u root -p mop<<EOF
use raji;
EOF
;;
esac
Enter password:
record inserted
Enter password:
record updated
Enter password:
record deleted
Enter password:
Enter password:
[2msc17@moplabs ~]$
MYSQL CONNECTIVITY USING C
Procedure:
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);
scanf("%d",&pid);
scanf("%s",pname);
scanf("%d",&qty);
scanf("%f",&price);
scanf("%s",edate);
itoa(qty,qty1,10);
sprintf(price1,"%f",price);
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");
#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);
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);
scanf("%d",&pid);
scanf("%d",&qty);
itoa(qty,qty1,10);
strcat(query,qty1);
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);
scanf("%d",&pid);
strcat(query,pid1);
q=mysql_query(c,query);
printf("record deleted\n");
#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);
scanf("%d",&pid);
itoa(pid,pid1,10);
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
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);
cin>>pid;
cin>>pname;
cin>>qty;
cin>>price;
cin>>edate;
itoa(qty,qty1,10);
sprintf(price1,"%f",price);
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);
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);
cin>>pid;
cin>>qty;
itoa(qty,qty1,10);
strcat(query,qty1);
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);
cin>>pid;
strcat(query,pid1);
q=mysql_query(c,query);
cout<<"record deleted"<<endl;
}
MYSQL CONNECTIVITY USING PHP
INSERT
<html>
<body>
</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"];
?>
UPDATE
<html>
<body>
</form>
</body>
</html>
<?php
$con= mysql_connect("localhost","root","");
mysql_select_db("raji",$con);
$pid=$_POST["pid"];
$qty=$_POST["qty"];
?>
DELETE
<html>
<body>
</form>
</body>
</html>
<?php
$con= mysql_connect("localhost","root","");
mysql_select_db("raji",$con);
$pid=$_POST["pid"];
?>
SELECT ALL
<html>
<body>
</form>
</body>
</html>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("raji",$con);
$b=$_POST["submit"];
if ($b = "submit")
while ($q=mysql_fetch_row($rs))
echo $q[4];
echo "<br>";