qinling072 发表于 2018-1-4 21:12:39

tomcat+mysql在Kubernetes环境

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>  
<%@ page import="java.sql.*" %>
  
<html>
  <head>
  <title>My JSP starting page</title>
  </head>
  <body>
  <h1>
  <%
  try {
  Class.forName("com.mysql.jdbc.Driver");
  String mysql_host=System.getenv("MYSQL_SERVICE_HOST");
  String mysql_port=System.getenv("MYSQL_SERVICE_PORT");
  Connection con=DriverManager.getConnection("jdbc:mysql://"+mysql_host+":"+mysql_port+"/mydb","root","welcome1");
  Statement state=con.createStatement();
  String sql2="select * from student";
  ResultSet rs=state.executeQuery(sql2);
  while(rs.next()){
  String uID=rs.getString("StuID");
  String uName=rs.getString("stuName");
  out.println("stuID:"+uID+""+"stuName:"+uName+"<br>");
  }
  out.println("Operator success..."+"<br>");
  state.close();
  con.close();
  } catch (Exception e) {
  e.printStackTrace();
  }
  %>
  </h1>
  </body>
  
</html>
页: [1]
查看完整版本: tomcat+mysql在Kubernetes环境