<%@ 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   ");
Out.print ("Latitude   ");
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