当前位置:网站首页>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
边栏推荐
- By asking where the variables are stored, the shepherd boy laughed and said to use pointers, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, the use of go lang type pointers (Poin
- 面试官:MySQL 中 update 更新,数据与原数据相同时会执行吗?大部分人答不上来!
- How to quickly get through the mirror release process?
- RTP
- socket实现TCP/IP通信
- unix环境编程 第十五章 15.8信号量
- 分类预测 | MATLAB实现CNN-LSTM(卷积长短期记忆神经网络)多特征分类预测
- 对话跨国消费品牌DPO:数据安全合规从何做起?8.11直播见!
- [贴装专题] 基于多目视觉的手眼标定
- 开源SPL,WebService/Restful广泛应用于程序间通讯,如微服务、数据交换、公共或私有的数据服务等。
猜你喜欢
随机推荐
Throwing a question? The execution speed of the Count operation in the Mysql environment is very slow. You need to manually add an index to the primary key---MySql optimization 001
basic operator
xmms已经发布到v1.3了,好久没写博客了
Win系统 - 罗技 G604 鼠标蓝灯闪烁、失灵解决方案
函数二
强化学习 (Reinforcement Learning)
字符串函数和内存函数
MySQL备份与恢复
机器学习--朴素贝叶斯(Naive Bayes)
函数组件和类组件和dva视图更新问题
动态内存管理
浅析JWT安全问题
多行省略和选择器
Master-slave postition changes cannot be locked_Slave_IO_Running shows No_Slave_Sql_Running shows No---Mysql master-slave replication synchronization 002
hover内部指定子类的样式
想了解API接口,这一篇就够了
借问变量何处存,牧童笑称用指针,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang类型指针(Pointer)的使用EP05
关于页面初始化
1003 我要通过! (20 分)
踩坑scrollIntoView