Tomcat connects to mysql database _ MySQL

Source: Internet
Author: User
Tomcat connects to the mysql database Tomcat

Today, I tried to connect to the mysql database. after successful connection, I wrote something. after all, the road to growth is still long.

<% @ Page contentType = "text/html" language = "java" errorPage = "" pageEncoding = "UTF-8" %> <% @ page import = "java. SQL. * "%>Welcome to xasasa<% // Register the database driver Class. forName ("com. mysql. jdbc. driver "); // Get the database Connection conn = DriverManager. getConnection ("jdbc: mysql: // mystruts2", "root", "leebt"); // create StatementStatement stmt = conn. createStatement (); // execute the query ResultSet rs = stmt.exe cuteQuery ("select * from students"); %>

  
 
  
   
<% // Traverse the result set while (rs. next () {%>

   
  <% }%> 
  
<% = Rs. getString (1) %> <% = Rs. getString (2) %>
This is the content of index. jsp. Mystuts2 is the database name and students is the table name. The specific values are inserted in mysql.


This is the result. In short, the code is not too complex and the principle is the most important.

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.