1,  传统的JDBC方法访问数据库

传统的JDBC方法访问数据库

JSP代码:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import ="java.sql.*,java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
 <%
  try
  {
     out.println("Is going to create Database connecting"); 
     out.println("<br>");
     //Class.forName("com.mysql.jdbc.Driver");// 动态加载mysql驱动
     //out.println("成功加载MySQL驱动程序");
     // out.println("<br>");  
     //链接数据库的集中URL的写法
     Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/wyswust1","root","000000");
    //Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/wyswust1?user=root&password=djl91600");
    // Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/wyswust1?useUnicode=true&characterEncoding=utf-8&useSSL=false&" + "user=root&password=000000");
    out.println("Database connected");
    out.println("<br>"); 
    Statement statement=con.createStatement();
    ResultSet resultSet=statement.executeQuery("select market_price,shop_price,pimage from wyswust1.product where pname='HTC One M9+' or pid=1");
    
    while(resultSet.next())
    {
      out.println(resultSet.getString("market_price")+"\t"+resultSet.getString("shop_price")+"\t"+resultSet.getString("pimage"));
      //out.println(resultSet.getString(1)+"\t"+resultSet.getString(2)+"\t"+resultSet.getString(3));
      out.println("<br>");
    }
    resultSet.close();
    con.close();
  }
  catch(Exception e)
  {
  }   
  %> 
</body>
</html>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2021-12-21
  • 2021-09-08
  • 2021-11-27
  • 2021-08-09
  • 2021-07-12
猜你喜欢
  • 2022-01-25
  • 2021-09-30
  • 2021-10-12
  • 2022-12-23
  • 2021-09-16
  • 2021-09-16
相关资源
相似解决方案