Connecting JSP to mysql

Source: Internet
Author: User


Download Connector/j(mysql()and php ))-connector-java-3.1.0-alpha.zip) from www. MySQL (the best combination with PHP). com, decompress,
Copy the MySQL (the best combination with PHP) in it-connector-java-3.1.0-alpha-bin.jar to the WEB-INF directory

Create test. jsp (preferred for SUN Enterprise applications) and restart tomcat (a very useful JSP running platform) Server
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Body>
<%
Class. forName ("org. gjt. mm. MySQL (the best combination with PHP). Driver"). newInstance ();
String url = "jdbc: MySQL (the best combination with PHP): // localhost/liufei_com? User = root & password = & useUnicode = true & characterEncoding = 8859_1 ";
// TestDB is your database name
Connection conn = DriverManager. getConnection (url );
Statement stmt = conn. createStatement (ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_UPDATABLE );
String SQL = "select * from users ";
ResultSet rs1_stmt.exe cuteQuery (SQL );
While (rs. next () {%>
The content of your first field is: <% = rs. getString (1) %>
Your second field content is: <% = rs. getString (2) %> <br>
<% }%>
<% Out. print ("database operation successful, congratulations"); %>
<% Rs. close ();
Stmt. close ();
Conn. close ();
%>
</Body>
</Html>

 

Related Article

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.