Using a JSP to make access to the database

Source: Internet
Author: User

<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
<%@ page contenttype= "text/html; charset=gb2312 "%>
<%@ page language= "java"%>
<%@ page import= "Com.mysql.jdbc.Driver"%>
<%@ page import= "java.sql.*"%>
<%
Driver name
String drivername= "Com.mysql.jdbc.Driver";
Database user Name
String username= "root";
Password
String userpasswd= "123";
Database name
String dbname= "Zzga";
Table name
String tablename= "T_device";
Junction string
String url= "jdbc:mysql://localhost/" +dbname+ "user=" +username+ "&password=" +USERPASSWD;
Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();
Connection connection=drivermanager.getconnection (URL);
Statement Statement = Connection.createstatement ();
String sql= "SELECT * from" +TABLENAME;
ResultSet rs = statement.executequery (SQL);
Get a collection of data results
ResultSetMetaData Rmeta = Rs.getmetadata ();
Determine the number of columns in a dataset, and also the number of fields
int Numcolumns=rmeta.getcolumncount ();
Out.print ("Precision of the &nbsp&nbsp");
Out.print ("Latitude &nbsp&nbsp");
Out.print ("Address");
Out.print ("<br>");
Output each data value
while (Rs.next ()) {

Out.print (Rs.getstring (4) + "");

Out.print ("|");

Out.print (Rs.getstring (5));
Out.print ("|");

Out.print (Rs.getstring (3));

Out.print ("<br>");

}
Out.print ("Successful database operation, congratulations");
Rs.close ();
Statement.close ();
Connection.close ();
%>

Using a JSP to make access to the database

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.