当前位置:网站首页>Database connection operations for MySQL and MyEclipse
Database connection operations for MySQL and MyEclipse
2022-08-09 10:28:00 【Zuo Mingshui】
1. The MySQL database and MyEclipse software have been installed correctly.
2. I set up the database school (name) and table (StudentInfo) under the doc
After entering the doc: refer to the relevant code
show databases;
Show all databases
exit;
Launch doc
create database School;
Create a database
use School;
Enter database
create table StudentInfo(
name char(10),
age char(3));
Create table
insert StudentInfo(name,age)
VALUES('David','18');
Insert data
select from StudentInfo;
Query
update StudentInfo set age='12' where name='HAHA';
Update data
insert into studentInfo (name,age)values('Jingzhu',20);
Insert data
delete from StudentInfo where age='20';
Delete data
3. Create a Javaproject (named Show) in MyEclipsemysql-connector-java-5.0.8-bin.jar in the downloaded JdbC compressed package)
Fourth, create a class (named Show) and related test code as follows:
import java.sql.;
public class Show
{
public static void main(String[] args)
{
try
{
String url="jdbc:mysql://localhost:3306/school";//school is the name of the database to be connected
String user="root";
Stringpwd="root";
//Load mysql driver, this sentence can also be written as: Class.forName("com.mysql.jdbc.Driver").newInstance();Class.forName("com.mysql.jdbc.Driver");//Call the method of the DriverManager object to obtain a Connection object, representing an open connection.Establish a connection with MySQL.Connection conn = DriverManager.getConnection(url, user, pwd);//Use the method of the Connection interface to create a Statement statement object, which is used to pass a simple SQL statement without parameters to the database management system for execution.Statement stmt = conn.createStatement();ResultSet rs = stmt.executeQuery("select * from studentInfo");// process the result setwhile (rs.next()){String name = rs.getString("name");System.out.print("name-----"+name);String age=rs.getString("age");System.out.println("age------"+age);}//close the connectionrs.close();stmt.close();conn.close();}catch (Exception ex){System.out.println("Error : " + ex.toString());}}
}
5. Running results.
name-----HAHA age------12
name-----David age------18
If the result is as follows, the connection to the database is successful.
6. Follow-up questions?
How to solve the problem of garbled characters in the running result?
name-----HAHA age------12
边栏推荐
- 壁纸
- 实现下拉加载更多
- 机器学习--线性回归(Linear Regression)
- 排序1:冒泡排序
- StratoVirt 中的虚拟网卡是如何实现的?
- Master-slave postition changes cannot be locked_Slave_IO_Running shows No_Slave_Sql_Running shows No---Mysql master-slave replication synchronization 002
- Electron application development best practices
- markdown转ipynb--利用包notedown
- 如何快速打通镜像发布流程?
- 3D打印了这个杜邦线理线神器,从此桌面再也不乱了
猜你喜欢
随机推荐
Nodejs服务端
Loop nesting and basic operations on lists
1005 继续(3n+1)猜想 (25 分)
EndNote User Guide
How to quickly get through the mirror release process?
unix环境编程 第十五章 15.8信号量
xmms的均衡器试验成功 音效相当不错 比rockbox可能还要好
自定义类型:结构体,枚举,联合
Master-slave postition changes cannot be locked_Slave_IO_Running shows No_Slave_Sql_Running shows No---Mysql master-slave replication synchronization 002
极域Killer 1.0代码
Win32控件------------显示系统使用的控件版本
源代码阅读器项目
按键精灵之输出文本
antd表单
函数二
深度学习--神经网络(基础讲解)
2021-01-11-雪碧图做表情管理器
Win系统 - 罗技 G604 鼠标蓝灯闪烁、失灵解决方案
可能95%的人还在犯的PyTorch错误
OpenGL 2.0编程例子







