derby数据库windows自带的客户端
本示例演示用windows自带的ij来操作derby数据库,包括建库,建表,插入数据,查询数据
首先要配置环境变量:
其次打开cmd输入如下图所示的命令:
java代码如下:
package com.adapter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; /** * @author Abraham Qin * @since 2019/1/19 */ public class DerbyTest { public static void main(String[] args) throws Exception{ Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); Connection connection = DriverManager.getConnection("jdbc:derby:mydb;create=true"); Statement statement = connection.createStatement(); statement.execute("drop table Greetings"); int update = statement.executeUpdate("CREATE TABLE Greetings (Message CHAR(40))"); statement.executeUpdate("INSERT INTO Greetings VALUES('hello')"); System.out.println(update); ResultSet resultSet = statement.executeQuery("select * from Greetings"); while(resultSet.next()){ System.out.println(resultSet.getString("Message")); } } }
注意上面的代码必须引入derby.jar这个jar包