<%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> Navigating in a Database Table
Welcome Guest !
Name
City
Phone
<% String name = request.getParameter("name"); String city = request.getParameter("city"); String phone = request.getParameter("phone"); String connectionURL ="jdbc:mysql://192.168.10.13:3306/ankdb"; Connection connection = null; PreparedStatement pstatement = null; Class.forName("com.mysql.jdbc.Driver").newInstance(); int updateQuery = 0; if(name!=null && city!=null && phone!=null){ if(name!="" && city!="" && phone!="") { try { connection = DriverManager.getConnection(connectionURL,"root","root"); String queryString = "INSERT INTO stu_info(Name,City,Phone) VALUES (?, ?, ?)"; pstatement = connection.prepareStatement(queryString); pstatement.setString(1, name); pstatement.setString(2, city); pstatement.setString(3, phone); updateQuery = pstatement.executeUpdate(); if (updateQuery != 0) { %>
Data is inserted successfully in database.
<% } } catch (Exception ex) { out.println("Unable to connect to batabase."); } finally { pstatement.close(); connection.close(); } } } %>