时间:2021-07-01 10:21:17 帮助过:61人阅读
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%
String driverName="com.mysql.jdbc.Driver";//驱动程序名
String userName="root";//数据库用户名
String userPasswd="qwe";//密码
String dbName="test";//数据库名
String tableName="location";//表名
//联结字符串
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);
int size = rs.getRow();//数据行数
ResultSetMetaData rmeta = rs.getMetaData();//获得数据结果集合
int numColumns=rmeta.getColumnCount();//确定数据集的列数,亦字段数
//输出每一个数据值
out.print(size+" ");
out.print("
");
while(rs.next()) {
out.print(rs.getString(1)+" ");//编号
out.print("|");
Double point1=rs.getDouble(4);
Double point2=rs.getDouble(3);
out.print(point1+" ");//输出经度
out.print(point2+" ");//输出纬度
out.print("
");
}
%>