8Oracle8/8i/9i数据库(thin模式)
//import javasql;
ClassforName("oraclejdbcdriverOracleDriver")newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
Connection conn= DriverManagergetConnection(url,%%2,%%3);
Statement stmtNew=conncreateStatement();
20数据库存入二进制字段数据
InputStream pic = new FileInputStream(dtoget(i)getLibPic());
sql = "INSERT INTO piclib (name,pic,sign,remark) VALUES (,,,)";
pstmt = conprepareStatement(sql);
pstmtsetString(1, dtoget(i)getName());
pstmtsetBinaryStream(2,pic,(int)dtoget(i)getLibPic()length());
21数据库取出二进制字段数据
//import javasql;
public class DemoDisplayBinaryDataFromDatabase {
public static Connection getConnection() throws Exception {
String driver = "oraclejdbcdriverOracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:databaseName";
String username = "name";
String password = "password";
ClassforName(driver);
Connection conn = DriverManagergetConnection(url, username, password);
return conn;
}
public static void main(String args[]) throws Exception {
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
String query = "SELECT raw_column, long_raw_column FROM binary_table WHERE id = ";
try {
conn = getConnection();
Object[] results = new Object[2];
pstmt = connprepareStatement(query);
pstmtsetString(1, "0001");
rs = pstmtexecuteQuery();
rsnext();
// materialize binary data onto client
results[0] = rsgetBytes("RAW_COLUMN");
results[1] = rsgetBytes("LONG_RAW_COLUMN");
} finally {
rsclose();
pstmtclose();
connclose();
}
}
}
在SERVLET中用SQL表达式把数据库中要查找的内容取出来
如果是多条 可以放入一个集合里
然后把集合放入REQUEST里 在容转发 把转到JSP页面 引用C标签
用C标签里的FOREACHE 把集合便利出来 用EL表达式接受${ }
以上就是关于用java从Oracle数据库取数据全部的内容,包括:用java从Oracle数据库取数据、在Java中如何实现从数据库中获取数值在文本框中得到、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)