• jdbc创建数据库的连接


    package com.gylhaut.db;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;

    public class DBUtil {
    //databaseweb数据库名称
    private static final String URL="jdbc:mysql://localhost:3306/databaseweb";
    private static final String NAME="root";
    private static final String PASSWORD="123456";

    public static void main(String[] args) throws Exception{
    //1.加载驱动程序
    Class.forName("com.mysql.jdbc.Driver");
    //DriverManager.registerDriver(new com.mysql.jdbc.Driver());
    //2.获得数据库的连接
    Connection conn= DriverManager.getConnection(URL,NAME,PASSWORD);
    //2.获得数据库的连接
    Statement stmt= conn.createStatement();

    ResultSet rs= stmt.executeQuery("select user_name,age from imooc_goddess");
    while(rs.next()){
    System.out.println(rs.getString("user_name") + "," +rs.getInt("age"));
    }
    }
    }

  • 相关阅读:
    English Dictionary site for ODE and OALD
    vmic environment
    makefile
    the diference between include and import
    windows 工具命令 cmd
    python namespace
    shell cmd args
    ROE, ROC
    IP
    链接及常用软件
  • 原文地址:https://www.cnblogs.com/gylhaut/p/7636783.html
Copyright © 2020-2023  润新知