博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
application下的JDBC操作
阅读量:4357 次
发布时间:2019-06-07

本文共 1194 字,大约阅读时间需要 3 分钟。

新建 project名称为TextJDBC,在src文件夹下新建com.zss.www的包,并在包里建个class:UseDadabase

在MySQL中建立一个lb的库,并在其建立表:student,表中包涵name,age,sex

UseDadabase代码如下:

package com.zss.www;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import com.mysql.jdbc.Connection;public class UseDadabase {    public static void main(String[] args) throws Exception {        // TODO Auto-generated method stub        String driver="com.mysql.jdbc.Driver";        String url="jdbc:mysql://localhost:3306/lb";        String username="root";        String password="11";        Connection conn=null;        Class.forName(driver);        conn=(Connection) DriverManager                .getConnection(url,username,password);        Statement stmt=null;        ResultSet rs=null;        stmt=(Statement) conn.createStatement();        rs=stmt.executeQuery("select*from student");        while(rs.next()){            System.out.println("name="+rs.getString(1));            System.out.println("age="+rs.getString(2));            System.out.println("sex="+rs.getString(3));        }        rs.close();        stmt.close();        conn.close();            }}

 

转载于:https://www.cnblogs.com/bgd150809319/p/6648884.html

你可能感兴趣的文章
图的遍历(bfs+dfs)模板
查看>>
angular service 进行组件通信
查看>>
linux安装Mac的默认Monaco字体
查看>>
java语言的特点
查看>>
关于动态添加iview admin路由以及刷新侧边栏
查看>>
ApplicationInsights的探测器尝鲜
查看>>
java 解析Json格式数据
查看>>
unix中的线程池技术详解
查看>>
CSS简介
查看>>
常用三大软件评价1
查看>>
MVC各层介绍使用---初步理解
查看>>
单例对象的创建与销毁
查看>>
知识点关键词(记录一下)
查看>>
国际结算业务
查看>>
嵌套循环概念
查看>>
C# 生成订单号的几种方式
查看>>
IOS开发札记
查看>>
1.2.2 OSI参考模型 上
查看>>
centos服务器设置代理上网的方法
查看>>
Linux企业运维高效技巧心得及分享
查看>>