import com.mysql.jdbc.Driver; import java.sql.Connection; import java.sql.
DriverManager; import java.sql.SQLException; import java.sql.Statement; public
class TestJDBCConnection { public static void main(String[] args) { //第一步:注册驱动
Statement statement=null; Connection connection=null; try { DriverManager.
registerDriver(new com.mysql.jdbc.Driver()); //第二步:创建连接 String url=
"jdbc:mysql://127.0.0.1:3306/mobilemallsystem"; String user="root"; String
password="123456"; connection= DriverManager.getConnection(url,user, password);
// System.out.println("数据库连接对象"+connection); //第三步:获取数据库操作对象(SQL语句执行对象)
statement= connection.createStatement(); //第四步:执行SQL语句 String sql="insert into
usermessage(uname,upassword) values('666','666')"; statement.executeUpdate(sql);
//第五步:处理查询结果集 //第六步:释放资源 } catch (SQLException throwables) { throwables.
printStackTrace(); }finally { if(statement!=null){ try { statement.close(); }
catch (SQLException throwables) { throwables.printStackTrace(); } } if(
connection!=null){ try { connection.close(); } catch (SQLException throwables) {
throwables.printStackTrace(); } } } } }

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信