保存java对象到数据库,并从数据库读出生成用户界面
向数据库保存对象,采用ObjectOutputStream向数据库直接写入
/**
* Title: AF
* Description: 向数据库中写入对象测试程序
* Copyright: Copyright 2009 ufgov, Inc.
* Company: ufgov
* 创建时间: 2009-10-29
* @author 刘永伟(manlge)
* @version 1.0
*/
public class WriteObjectToBlob {
/*
* 建表sql
* CREATE TABLE "AF"."TABLE2" ("NAME" VARCHAR2(36) NOT NULL, "DATA" BLOB NOT NULL) TABLESPACE "AF"
*/
public static Connection getConnection(String host, int port, String dataBaseName,
String userName, String password) throws Exception {
String url = String.format("jdbc:oracle:thin:@%s:%s:%s", host, port,
dataBaseName);
String driver = "oracle.jdbc.driver.OracleDriver";
Class.forName(driver);
Connection con = DriverManager.getConnection(url, userName, password);
return con;
}
/**
* @param args
* @throws SQLException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws Exception {
Connection connection = getConnection("localhost", 1521, "ORCL", "AF", "1");
System.out.println(connection);
connection.setAut
相关文档:
首先,做一点说明。Flex是不能直接连接数据库的,这一点大家需要知道,它只能间接地连接数据库。Flex中提供了三种方式:HttpService,WebService 和RemoteObject。其中HttpService可以直接获取XML中的数据,还可以通过JSP,ASP以及PHP读取数据库中的数据,这个比较简单,而且网上也有很多例子,我就不多说了。WebServi ......
package day10;
import java.util.*;
public class MyLinkedList implements List
{
static class Node
{
public Object data;
public Node next;
public Node(Object data)
{
this.data=data;
}
}
private Node head;
public MyLinkedList()
{
head=new Node(0);
}
public void add(int ind ......
java获取当前路径
1、利用System.getProperty()函数获取当前路径:
System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径
2、使用File提供的函数获取当前路径:
File directory = new File("");//设定为当前文件夹
try{
System.out.println(directory.getCano ......
花了大半天的时间终于解决了问题,下面分享一下我的过程:
我的系统安装的是jdk6,netbeans和Mycrosoft SqlServer 2005,java连接数据库一般要分六部走
1.注册驱动
2.用驱动管理类创建连接
3.创建语句statement封装sql脚本语句
4.执行
5.处理返回的结果
6.关闭相关连接
在这里连接的是SqlServer2005,属于第三方驱动 ......
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.Serializable;
import java.rmi.Na ......