JSP code
<%@page import="java.sql.*"%>
<%!
int prod_id=1;
String prod_name="Laptop";
int qty=2;
float price=22000.30f;
%>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:NaveenRahul");
Statement st=con.createStatement();
String query="insert into product values("+prod_id+",'"+prod_name+"',"+qty+","+price+")";
if(st.executeUpdate(query)>0){
out.write("Records inserted");
}else{
out.write("insertion faild");
}
}catch(Exception e){
out.write("Exception : "+e);
}
%>
JAVA Codes
import java.sql.*;
class Insert2{
public static void main(String ar[]){
int prod_id=2;
String prod_name="Laptop";
int qty=2;
float price=22000.30f;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:NaveenRahul");
Statement st=con.createStatement();
String query="insert into product values("+prod_id+",'"+prod_name+"',"+qty+","+price+")";
if(st.executeUpdate(query)>0){
System.out.println("Records inserted");
}else{
System.out.println("insertion faild");
}
con.close();
}catch(Exception e){
System.out.println("Exception : "+e);
}
}
}
Comments