JABC connect to database to handle garbled problems when adding data

Source: Internet
Author: User


<% @page import= "java.sql.*"%>
<% @page contenttype= "text/html" pageencoding= "UTF-8"%>
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> access the database through the MySQL JDBC driver </title>
<body>
<table border= "1" bgcolor= "#ccceee" align= "Center" >
<tr>
<th width= "" align= "Center" > Study No. </th>
<th width= "" align= "center" > Name </th>
<th width= "align=", "center" > Professional </th>
</tr>
<%
Connection Con=null;
Statement Stmt=null;
ResultSet Rs=null;
Class.forName ("Com.mysql.jdbc.Driver");
/*3306 is the port number, student is the database name, the URL is appended to the USEUNICODE=TRUE&AMP;CHARACTERENCODING=GBK, is to handle the problem of garbled when adding data to the database. */
String url= "JDBC:MYSQL://LOCALHOST:3306/STUDENT?USEUNICODE=TRUE&AMP;CHARACTERENCODING=GBK";
Con=drivermanager.getconnection (URL, "root", "root");
Stmt=con.createstatement ();
String sql= "SELECT * from Sinfo";
Rs=stmt.executequery (SQL);
while (Rs.next ()) {
%>
<tr>
<td><%=rs.getstring ("Studentnumber")%></td>
<td><%=rs.getstring ("Studentname")%></td>
<td><%=rs.getstring ("StudentClass")%></td>

</tr>
<%
}
Rs.close ();
Stmt.close ();
Con.close ();
%>
</table>
</body>

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.