运行这个客户端之前要先运行
学习Java6(六) 嵌入式数据库Derby(4)网络版服务端中的服务端
1 import java.sql.Connection;
2 import java.sql.DriverManager;
3 import java.sql.ResultSet;
4 import java.sql.Statement;
5
6 public class TestDerbyClient {
7 public static void main(String[] args) {
8 String URL = "jdbc:derby://127.0.0.1:1527/TESTDB;create=true";
9 try {
10
11 Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();//加载驱动
12 Connection conn = DriverManager.getConnection(URL);//建立连接
13
14 Statement st = conn.createStatement();
15 ResultSet rs = st.executeQuery("select * from USER_INFO");//读取数据
16 while(rs.next()){
17 int id = rs.getInt(1);
18 String name = rs.getString(2);
19 System.out.println("ID="+id);
20 System.out.println("NAME="+name);
21 }
22
23 } catch (Exception ex) {
24 ex.printStackTrace();
25 }
26 }
27 }
运行输出:
ID=1
NAME=hermit
ID=2
NAME=test
posted on 2007-01-16 17:52
交口称赞 阅读(1619)
评论(0) 编辑 收藏 所属分类:
Java6