MyEclipse 连接MySQL数据库

    xiaoxiao2021-11-10  42

    MyEclipse 连接MySQL数据库

    首先连接好数据库 :http://jingyan.baidu.com/article/4e5b3e196758ad91901e24a0.html 连接步骤很详细。 对于数据库的操作 1、首先加载JDBC驱动程序 这里面使用java.lang.class类的静态方法forName。

    Class.forName("com.mysql.jdbc.Driver");//加载jdbc驱动程序

    2、创建数据库的连接

    Connection conn = (Connection) DriverManager.getConnection( "jdbc:mysql://127.0.0.1:3306/数据表名", "root", "密码");

    3、数据库查询

    Statement stmt = (Statement) conn.createStatement(); ResultSet rs = stmt .executeQuery("select * from table");

    4、数据库插入 直接插入:

    statement.excuteUpdate( "INSERT INTO staff(****)" + " VALUES (**** ) ") ;

    插入:

    PreparedStatement stmt = (PreparedStatement) conn .prepareStatement("INSERT INTO table VALUES(?,?,...)"); stmt.setString(1, variable); stmt.setDate(2, variable); ...

    参考微博: [1].believejava. 在myeclipse中连接mysql查询数据 [EB/OL].http://blog.csdn.net/believejava/article/details/35284267 [2]【转】myeclipse中连接mysql数据库.http://www.cnblogs.com/sunada2005/p/3533224.html

    转载请注明原文地址: https://ju.6miu.com/read-678156.html

    最新回复(0)