The connection problem between MySQL and Eclipse
来源:互联网 发布:利用xampp进入mysql 编辑:程序博客网 时间:2024/05/05 01:59
1.Download and install "Eclipse"
You can refer to: http://blog.csdn.net/zxm490484080/article/details/52403307
2.Download and install "MySQL"
You can refer to: http://blog.csdn.net/sinat_34817187/article/details/51283595
Running program:The above results indicate that you have successfully connected the database
You can refer to: http://blog.csdn.net/zxm490484080/article/details/52403307
2.Download and install "MySQL"
You can refer to: http://blog.csdn.net/sinat_34817187/article/details/51283595
3.Download "mysql-connector-java.jar"
4.
4.1 cmd;
4.2 Enter: mysql -u root -p click Enter
4.3 Enter password click Enter
4.4 :
5.Next, create a data
mysql>CREATE DATABASE test; //create a databasemysql>use test; //Specify test as the database to be operated onmysql>CREATE TABLE user (name VARCHAR(20),password VARCHAR(20)); //create a table user,Set two fields.mysql>INSERT INTO user VALUES('huzhiheng','123456'); //Insert a data into a table
6.Open Eclipse and create a project,
Specific operations : right click my--->build Path--->Add external Archiver...select the "mysql-connector-java.jar"
7.The drive has been imported,let us write a program to verify it:
package com.nuist.One;import java.sql.*;public class ArrayOne { public static void main(String args[]) { try { Class.forName("com.mysql.jdbc.Driver"); //加载MYSQL JDBC驱动程序 //Class.forName("org.gjt.mm.mysql.Driver"); System.out.println("Success loading Mysql Driver!"); } catch (Exception e) { System.out.print("Error loading Mysql Driver!"); e.printStackTrace(); } try { Connection connect = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","599494."); //连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码 System.out.println("Success connect Mysql server!"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from user"); //user 为你表的名称while (rs.next()) { System.out.println(rs.getString("name")); } } catch (Exception e) { System.out.print("get data error!"); e.printStackTrace(); } }}
Success loading Mysql Driver!Success connect Mysql server!LeiYi
8.The following example inserts 200 data into the user table of MySQL
import java.sql.*;publicclass ArrayOne { publicstaticvoid main(String args[]) { try { Class.forName("com.mysql.jdbc.Driver"); //加载MYSQL JDBC驱动程序 //Class.forName("org.gjt.mm.mysql.Driver"); System.out.println("Success loading Mysql Driver!"); } catch (Exception e) { System.out.print("Error loading Mysql Driver!"); e.printStackTrace(); } try { Connection connect = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","599494."); int num=100; PreparedStatement Statement=connect.prepareStatement("INSERT INTO user VALUES(?,?)"); for(int i=0;i
9.Next, we open the MySQL database for viewing
mysql> show databases;
mysql> use test;
mysql> show tables;
mysql> select *from user;
OK!!
阅读全文
0 0
- The connection problem between MySQL and Eclipse
- the difference between Oracle and Mysql
- What's the difference and connection between API(Application Programming Interface) and SC(System Call)?
- The difference between (()) and ().
- What is the difference between BIT and TINYINT in MySQL
- mysql update between and
- Mysql,Between And时间
- mysql connection problem fix
- The SSH connection between computers without passwords
- 【MongoDB】The connection between two tables
- mysql connection AND sqlserver connection
- the difference between "./" and "sh"
- mysql between and date formats
- sql between...and 用法(mysql)
- the difference between the SOURCELIBS and TARGETLIBS
- Difference between "Primary DNS Suffix" and "Connection specific DNS Suffix"?
- The Intetresting Words between English and Chinese
- The difference between Const and ReadOnly
- H5本地存储-indexedDB数据库(一)
- Shell printf 命令
- Docker学习记录(2)——JAVA应用容器化(JAVA博客应用Solo)
- 浅谈oracle表约束---cxl
- VMware CentOS 7 安装 VMware Tools(修复不能与主机共享文件的错误) 与 控制台分辨率设置
- The connection problem between MySQL and Eclipse
- uva 11752 The Super Powers
- Android入门笔记汇总
- PHP编程中经常需要用到一些服务器的一些资料
- 设计模式之单例模式
- 交换机的背板带宽,交换容量,包转发率区别以前计算公式
- Java 同步框架 AQS 深入分析
- java服务器端判断页面请求是否为ajax请求
- Android 图片的缩放以及滑动