Introduction to the JDBC driver of MM. MySQLMySQL _ MySQL

Source: Internet
Author: User
Mm. mysql is a mysql JDBC driver of Type 4 (pure java) that complies with the jdbc2 specification. The current version is 2.0pre5 (beta. worldserver. commm. mysql downloads the latest driver. This article only briefly describes mm. install and use mysql 1. download mm. mysql2, extract to a drive, such as c: 3, modify clas JDBC


Mm. mysql is a mysql jdbc driver of Type 4 (pure java) that complies with jdbc 2 specifications. The current version is 2.0 pre 5 (beta). you can download the latest driver from http://www.worldserver.com/mm.mysql/. this document is just a simple example of installing and using mm.mysql.
  
   Install
1. download mm. mysql
2. decompress the package to a drive, such as c:
3. modify the classpath and add the path of mm. mysql. for example, your original classpath may be:
.; C: jdk1.2.2lib ools. jar; c: jdk1.2.2libdt. jar;
After modification, it may be
.; C: jdk1.2.2lib ools. jar; c: jdk1.2.2libdt. jar; C: mm. mysql. jdbc-2.0pre5;
  
   Programming
1. use DriverManager to register mm. mysql
The class name of mm. mysql is org. gjt. mm. mysql. Driver. it must be written during registration.
Class. forName ("org. gjt. mm. mysql. Driver"). newInstance ();
  
2. jdbc url parameter description
Url format: jdbc: mysql: // [hostname] [: port]/dbname [? Param1 = value1] [m2 = value2]...
Default parameter name
User Database user name none
Password database user password unavailable
AutoReconnect determines whether to automatically connect when the database connection is lost. The value is true/false.
MaxReconnects if autoReconnect is true, this parameter indicates the number of retries. the default value is 3.
InitialTimeout if autoReconnect is true, this parameter is the number of seconds waiting before reconnection 2
MaxRows sets the number of rows returned during the query. 0 indicates all 0
Whether useUnicode uses unicode output, true/false
CharacterEncoding if useUnicode, this parameter is set to the encoding type. it is recommended that you use 8859_1
  
   Prompt
At the same time, useUnicode and characterEncoding can be used to solve Chinese problems in database output.
For example, jdbc: mysql: // localhost/test? User = root & useUnicode = true; characterEncoding = 8859_1
  
A simple example
This jsp example uses a library, which has only one table (address book)
  
Create database addressbook
Use addressbook
Create table addressbook (id int auto_increment primary key, name varchar (30), address varchar (255), phone varchar (20 ));
  
   Insert record
Insert into addressbook (name, address, phone) values ('jx', 'Zhejiang yuyao ', '2017-0574 ');
  
Jsp code: absolute, ResultSet. TYPE_SCROOL_SENSITIVE and other directories are used in the code to test whether mm. mysql complies with jdbc 2.0 specifications.
<% @ Page import = "java. SQL. *" %>
<%
Out. println ("address book! ");
  
Try {
Class. forName ("org. gjt. mm. mysql. Driver"). newInstance ();
  
}
Catch (Exception E ){
Out. println ("Unable to load driver .");
  
}
  
Try {
Connection C = DriverManager. getConnection ("jdbc: mysql: // localhost/addressbook? User = root & password = jjx & useUnicode = true & characterEncoding = 8859_1 ");
Statement s = C. createStatement (ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_READ_ONLY );
ResultSet rs=s.exe cuteQuery ("select * from addressbook ");
Out. println ("















");Int I = 1;For (I = 10; I <20; I ++){If (rs. absolute (I )){Out. println (" ");Out. println (" ");Out. println (" ");}Else{Break;}  }Out. println ("
");
Out. println (rs. getString (1 ));
Out. println ("
");
Out. print (rs. getString (2 ));
Out. println ("
");
Out. print (rs. getString (3 ));
Out. println ("
");
Rs. close ();
S. close ();
C. close ();
  
}
Catch (SQLException E ){
Out. println ("SQLException:" + E. getMessage ());
Out. println ("SQLState:" + E. getSQLState ());
Out. println ("VendorError:" + E. getErrorCode ());
}
  
%>

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.