package com.umt.DBTest.dbtest;import java.sql.*;public class JDBCTest { /** * @param args * @throws ClassNotFoundException * @throws SQLException */ public static void main(String[] args) throws ClassNotFoundException, SQLException { // TODO Auto-generated method stub //第一步:打开数据库 需要用户名,密码,数据库地址,数据库名称; String username = "root"; String password = "123456"; String url = "jdbc:mysql://localhost:3306/users"; //1.加载数据库驱动 Class.forName("com.mysql.jdbc.Driver"); //2.创建是数据库连接 Connection conn = DriverManager.getConnection(url, username, password); System.out.println("数据库连接成功!"); //第二步:操作数据库; String sql=" insert into user_table ( UserId,UserName,PassWord) values (5,'song','ss') "; PreparedStatement pt=conn.prepareStatement( sql ); pt.executeUpdate( ); //第三步:关闭数据库; conn.close(); System.out.println("数据库操作成功!"); } }