Mega Code Archive
Categories
/
Java Tutorial
/
JSP
Insert data to a table
<%@ page import="java.sql.*" %>
Filling a Table
Filling a Table
<% Connection connection = null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); connection = DriverManager.getConnection("jdbc:odbc:data", "YourName", "password"); Statement statement = connection.createStatement(); String command = "INSERT INTO Employees (ID, Name) VALUES (1, 'Tom')"; statement.executeUpdate(command); command = "INSERT INTO Employees (ID, Name) VALUES (2, 'Peter')"; statement.executeUpdate(command); ResultSet resultset = statement.executeQuery("select * from Employees"); while(resultset.next()){ %>
ID
Name
<%= resultset.getString(1) %>
<%= resultset.getString(2) %>
<% } %>