Erp|server I have given you the source code, how to connect with database from JSP. This are easy and simple.cut and paste the below code and modify according to your. This is esspecially to those who had coding experience in ASP. I have given proper documentation.
<!--we ' ve to import the necessary packages-->
<!--Importing Packages starts-->
<%@ page info= "Database handler"%>
<%@ page import= "java.io.*"%>
<%@ page import= "java.util.*"%>
<%@ page import= "java.sql.*"%>
<%@ page import= "javax.servlet.*"%>
<%@ page import= "javax.servlet.http.*"%>
<!--Importing Packages ends-->
<%
Try
{
Loading the drivers
This code loads JDBD-ODBC Driver
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
Making connection
The second step in establishing a connection are to have the appropriate
Driver connect to the DBMS. The following line of code illustrates the
General idea:
String url= "Jdbc:odbc:test";
Where "test" is the System DSN name
Connection con=drivermanager.getconnection (URL, "Administrator", "password");
Where, the administrator is the username to
Access the database and password is "password"
DriverManager ' s getconnection method estabilishes connection
With the database specified in the JDBC URL
Then Create JDBC Statement
Statement stmt = Con.createstatement ();
String query= "CREATE TABLE coffees" +
"(Cof_name VARCHAR (32)," +
"Sup_id INTEGER," +
"Price FLOAT," +
"SALES INTEGER," +
"Total INTEGER)";
Execute the statement
Stmt.executeupdate (query);
}
catch (Exception e) {}
Give confirmation message
OUT.PRINTLN ("Table coffees created");
%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.