Mysql4.1.10 JDBC Drive (Mysql-Connector-Java-3.1.7-bin.jar) configuration and test

xiaoxiao2021-03-06  41

Mysql4.1.10 JDBC driver configuration and testing. Download mysql4.1.10 Download: http://dev.mysql.com/get/downloads/mysql-4.1/mysql-4.1.10-win32.zip/from/pickmysql4 .1.10JDBC driver download: http://dev.mysql.com/get/downloads/connector-j/mysql-connector-java-3.1.7.zip/from/pickmysql-front download: mysql-front is an Easy To Use, Compact, And Very Fast Graphical Tool to Manage Your My MySQL Database - from anywhere in the world. http://www.mysqlfront.de/download.html II. Configuration 1. Put the downloaded JDBC Drive MySQL-Connector- Java-3.1.7.zip decompress, extract the mysql-connector-java-3.1.7-bin.jar file to the appropriate position, and set the ClassPath path to the file. 2. Install the MySQL database. 3. Install mysql- FRONT, use MySQL-Front to establish a database jtest and establish table info in Jtest. Third. Test test code is as follows: file name: testmysql.java / ** @Author rockaka * mysql JDBC driver test code * mysql4.1.10 mysql-connector-java-3.1.7-bin.jar * Data: 2005-02-23 * /

Import java.sql. *;

Public class testmysql {

Public static void main (String [] args) {// driver name string drivername = "com.mysql.jdbc.driver"; // Database User name string username = "root"; // password string userpasswd = "root" ; // Database name string dbname = "jtest"; // table name string Tablename = "info"; // couple string string url = "jdbc: mysql: // localhost /" DBNAME "? User =" username "& password =" userpasswd; system.out.println (URL); Try {class.forname ("com.mysql.jdbc.driver). NewInstance ();

Connection connection = DriverManager.getConnection (url); Statement statement = connection.createStatement (); String sql = "SELECT * FROM" tableName; ResultSet rs = statement.executeQuery (sql); // get the data results set ResultSetMetaData rmeta = rs .getmetadata (); // Determine the number of columns of the data set, and the number of field int numColumns = rmeta.getColumnCount (); // output each data value for (int i = 1; i <= numcolumns; i ) {IF (I ) {IF I

转载请注明原文地址:https://www.9cbs.com/read-54877.html

New Post(0)