1. Mysql在java中的使用步骤

时间:2025-01-14 10:04:50

-1.配置数据库:http://www.cnblogs.com/sshoub/p/4321640.html

2.创建可以远程的登录用户:http://www.cnblogs.com/xyzdw/archive/2011/08/11/2135227.html

grant all privileges on *.* to testuser@"%" identified by "password" ;

3.数据库操作:

  • 创建数据库以及表
DROP TABLE
IF EXISTS mq_message_content; CREATE TABLE mq_message_content (
task_id VARCHAR (255) NOT NULL CHECK (task_id != ''),
type VARCHAR (255) NOT NULL,
msgcontent LONGTEXT NOT NULL,
time VARCHAR (50) NOT NULL,
PRIMARY KEY (task_id, type)
) DEFAULT CHARSET = 'utf8';

4. Java代码连接数据库,进行相应的操作

Class.forName(dbDriver).newInstance();
Connection conn = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
PreparedStatement pst = conn.prepareStatement(sql);

相关文章