Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page import="java.sql.*" %>
- <%
- String url = "jdbc:odbc:productDSN";
- String username="";
- String password="";
- Connection conn=null;
- String classPath = "sun.jdbc.odbc.JdbcOdbcDriver";
- try{
- Class.forName(classPath);
- conn = DriverManager.getConnection(url,username,password);
- }catch(Exception exc){
- out.println(exc.toString());
- }
- Statement stm=null;
- string id = request.getParameter("id");
- string name = request.getParameter("name");
- string model = request.getParameter("model");
- string priceS = request.getParameter("price");
- string midS = request.getParameter("mid");
- float price=0;
- int mid=0;
- try{price = Float.parseFloat(priceS);}catch(Exception exc){}
- try{mid = Integer.parseInt(midS);}catch(Exception exc){}
- stm= conn.createStatement();
- String query = "INSERT INTO product VALUES('"+id+"', '" + name +"', '"+
- model + "'," + price +", "+ mid + ")";
- try{
- stm.executeUpdate(query);
- out.println("The data were added to the table successfully!");
- }catch(Exception exc){
- out.println("Inserting data failed!");
- }
- stm.close();
- conn.close();
- %>
- <br><br><a href="example5.html">Add more record</a>
Add Comment
Please, Sign In to add comment