自ORACLE 9i之后,Oracle提供了一个基于Web图形化数据管理工具Oracle企业管理器(Oracle Enterprise Manager),用来代替SQL命令来管理数据库。
Windows下OEM默认是开启的,可以直接访问,Linux下必须通过命令启动,相关命令如下:
--查看当前OEM状态
EMCTL STATUS DBCONSOLE;
--停止OEM
EMCTL STOP DBCONSOLE;
--启动OEM
EMCTL STRAT DBCONSOLE;
OEM的访问URL如下:
http://localhost:1158/em
如是本地访问则lcalhost本地服务的用户名,当远程访问OEM时则可输入远程服务器的IP地址。
在Linux下安装oracle后,Windows下访问OEM时会出现按钮中文乱码情况,解决方法如下:
1、停止OEM
[oracle@localhost ~]$ emctl stop dbconsole
TZ set to PRC
Oracle Enterprise Manager 10g DatabaseControl Release 10.2.0.1.0
Copyright (c) 1996, 2005 OracleCorporation. All rights reserved.
http://localhost.localdomain:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 10gDatabase Control ...
... Stopped.
2、找到如下路径:
$ORACLE_HOME/jdk/jre/lib
$ORACLE_HOME/jre/1.4.2/lib
,执行下列步骤
[oracle@localhost ~]$ cd/opt/oracle/product/10.2.0/db_1/jdk/jre/lib/
[oracle@localhost lib]$ cp font.propertiesfont.properties.1.bat
[oracle@localhost lib]$ cp font.properties.zh_CN.Redhatfont.properties
[oracle@localhost lib]$ cd/opt/oracle/product/10.2.0/db_1/jre/1.4.2/lib/
[oracle@localhost lib]$ cp font.propertiesfont.properties.1.bat
[oracle@localhost lib]$ cpfont.properties.zh_CN.Redhat font.properties
此时可以查看文件font.properties最后一行如下
filename.-misc-zysong18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1=/usr/share/fonts/zh_CN/TrueType/zysong.ttf
3、切换root用户查看是否存在文件/usr/share/fonts/zh_CN/TrueType/zysong.ttf,默认情况下是不存在此文件,如不存在,则可从Windows下C:/Windows/fonts找到中文字符文件,如不存在可用其他文件代替,替换文件名即可,推荐使用STSONG,处理结构如下所示:
[root@localhost ~]# cd/usr/share/fonts/zh_CN/TrueType/
[root@localhost TrueType]# ll
total 11440
-rwxrwxr-x 1 root root 11697600 Mar 8 13:53 zysong.ttf
需注意的是zysong.ttf文件名必须小写。
4、清楚OEM下的缓存图片
[oracle@localhost~]$cd/opt/oracle/product/10.2.0/db_1/oc4j/j2ee/oc4j_applications/applications/em/em/cabo/images/cache/zhs/
[oracle@localhost zhs]$ ll *.gif
-rw-r----- 1 oracle oinstall 1681 Mar 1211:07 b-0c_ASH_5.gif
-rw-r----- 1 oracle oinstall 1260 Mar 1210:05 b-3d-1.gif
-rw-r----- 1 oracle oinstall 1608 Mar 1210:05 b-61af-1.gif
……
[oracle@localhost zhs]$ rm *.gif
[oracle@localhost zhs]$ rm *.imx
5、重新启动OEM
[oracle@localhost zhs]$ emctl startdbconsole
TZ set to PRC
Oracle Enterprise Manager 10g DatabaseControl Release 10.2.0.1.0
Copyright (c) 1996, 2005 OracleCorporation. All rights reserved.
http://localhost.localdomain:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 10gDatabase Control ................................. started.
------------------------------------------------------------------
Logs are generated in directory/opt/oracle/product/10.2.0/db_1/localhost.localdomain_testdb/sysman/log
1、DBCollection的管理
package com.boonya.mongo; import java.util.Set; import com.mongodb.DBCollection; public class CollectionManager { public static DBCollection getDbCollection(String collectionName){ return DBConnection.getInstance().getCollection(collectionName.equals("")?"myCollection":collectionName); } public String getCollectionNames(){ String strNames=""; Set<String> colls =DBConnection.getInstance().getCollectionNames(); for (String cname : colls) { strNames+=cname+","; } return strNames; } }
2、并发操作管理
package com.boonya.mongo; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBObject; import com.mongodb.WriteConcern; public class ConcurrencyManager { private static DBCollection coll= CollectionManager.getDbCollection("myCollection"); /** * If you want to ensure complete consistency in a “session” (maybe an http request), * you would want the driver to use the same socket, which you can achieve by using a * “consistent request”. Call requestStart() before your operations and requestDone() * to release the connection back to the pool: * DB and DBCollection are completely thread safe. In fact, they are cached so you get * the same instance no matter what */ public void insertData(){ DB db=DBConnection.getInstance(); db.requestStart(); try { db.requestEnsureConnection(); //do something } finally { db.requestDone(); } } /** * Since by default a connection is given back to the pool after each request, you may * wonder how calling getLastError() works after a write. You should actually use a * write concern like WriteConcern.SAFE instead of calling getLastError() manually. * The driver will then call getLastError() before putting the connection back in the pool. * * WriteConcern.NONE No exceptions thrown. * WriteConcern.NORMAL Exceptions are only thrown when the primary node is unreachable for * a read, or the full replica set is unreachable. * WriteConcern.SAFE Same as the above, but exceptions thrown when there is a server error * on writes or reads. Calls getLastError(). * WriteConcern.REPLICAS_SAFE Tries to write to two separate nodes. Same as the above, but * will throw an exception if two writes are not possible. * WriteConcern.FSYNC_SAFE Same as WriteConcern.SAFE, but also waits for write to be written to disk. * */ public void writeConcern(){ coll.insert(new BasicDBObject("name","boonya").append("age", 21), WriteConcern.SAFE); // is equivalent to DB db=DBConnection.getInstance(); DBCollection coll=CollectionManager.getDbCollection("myCollection"); db.requestStart(); try { coll.insert(new BasicDBObject("name","boonya").append("age", 21)); DBObject err = db.getLastError(); System.out.println(err); } finally { db.requestDone(); } } }
3、数据库管理
package com.boonya.mongo; import java.net.UnknownHostException; import com.mongodb.MongoClient; public class DatabaseManager { public String getDatabaseNames() throws UnknownHostException{ String strNames=""; MongoClient mongoClient; mongoClient = new MongoClient(); for (String name : mongoClient.getDatabaseNames()) { strNames+=name+","; } return strNames; } public void dropDatabase(String databaseName) throws UnknownHostException{ MongoClient mongoClient = new MongoClient(); mongoClient.dropDatabase(databaseName); } }
4、文档管理
package com.boonya.mongo; import java.util.ArrayList; import java.util.List; import com.mongodb.BasicDBObject; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.DBObject; public class DocumentManager { private static DBCollection coll= CollectionManager.getDbCollection("myCollection"); public void insertADocument(){ BasicDBObject doc = new BasicDBObject("name", "MongoDB").append("type", "database") .append("count", 1) .append("info", new BasicDBObject("x", 203).append("y", 102)); coll.insert(doc); } /** * PRINT BELOW: * { "_id" : "49902cde5162504500b45c2c" , * "name" : "MongoDB" , * "type" : "database" , * "count" : 1 , * "info" : { "x" : 203 , "y" : 102}} * @return */ public DBObject findTheFirstDocument(){ System.out.println("collection count:"+coll.getCount()); DBObject myDoc = coll.findOne(); System.out.println(myDoc); return myDoc; } public List<DBObject> getADocumentsByCursor(){ List<DBObject> docs=new ArrayList<DBObject>(); DBCursor cursor =coll.find(); try { while(cursor.hasNext()) { DBObject obj=cursor.next(); System.out.println(obj); docs.add(obj); } return docs; } finally { cursor.close(); } } /** * PRINT LIKE THIS: * { "_id" : "49903677516250c1008d624e" , "i" : 71 } */ public void queryADocument(){ BasicDBObject query = new BasicDBObject("i", 71); DBCursor cursor =coll.find(); cursor = coll.find(query); try { while(cursor.hasNext()) { System.out.println(cursor.next()); } } finally { cursor.close(); } } public void editQueryRegular(){ //db.things.find({j: {$ne: 3}, k: {$gt: 10} }); BasicDBObject query = new BasicDBObject("j", new BasicDBObject("$ne", 3) .append("k", new BasicDBObject("$gt", 10))); DBCursor cursor = coll.find(query); try { while(cursor.hasNext()) { System.out.println(cursor.next()); } } finally { cursor.close(); } } public void getAsetDocument(){ BasicDBObject query = new BasicDBObject("i", new BasicDBObject("$gt", 50)); // e.g. find all where i > 50 // query = new BasicDBObject("i", new BasicDBObject("$gt", 20). // append("$lte", 30)); // i.e. 20 < i <= 30 DBCursor cursor = coll.find(query); try { while(cursor.hasNext()) { System.out.println(cursor.next()); } } finally { cursor.close(); } } }
5、索引管理
package com.boonya.mongo; import java.util.List; import com.mongodb.BasicDBObject; import com.mongodb.DBCollection; import com.mongodb.DBObject; public class IndexManager { private static DBCollection coll= CollectionManager.getDbCollection("myCollection"); public void createIndex(){ // create index on "i", ascending coll.createIndex(new BasicDBObject("i", 1)); } public List<DBObject> getIndexList(){ List<DBObject> list = coll.getIndexInfo(); for (DBObject o : list) { System.out.println(o); list.add(o); } return list; } }
6、预读取机制
package com.boonya.mongo; import com.mongodb.BasicDBObject; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.DBObject; import com.mongodb.ReadPreference; public class ReadPreferences { private static DBCollection coll= CollectionManager.getDbCollection("myCollection"); /** * ReadPreference.primary(); * ReadPreference.primaryPreferred(); * ReadPreference.secondary(); * ReadPreference.secondaryPreferred(); * ReadPreference.nearest(); */ public void read(){ DBObject query = new BasicDBObject("name", "simple doc"); //Read from primary if available, otherwise a secondary. ReadPreference preference = ReadPreference.primaryPreferred(); DBCursor cur = new DBCursor(coll, query, (DBObject) preference); //Read from any member node from the set of nodes which respond the fastest. //The responsiveness of a node is measured with pings. Any node whose ping //time is within 15 milliseconds of the node with the lowest ping time is considered near. DBObject result =coll.findOne(query, (DBObject) ReadPreference.nearest()); // initialize a properly tagged read preference ReadPreference tagged_pref =ReadPreference.secondaryPreferred(new BasicDBObject("datacenter", "Los Angeles")); // include the tagged read preference in this request}} DBObject result1=coll.findOne(new BasicDBObject("name", "simple doc"), (DBObject) tagged_pref); // read from either LA or US_West DBObject tagSetOne = new BasicDBObject("datacenter", "Los Angeles"); DBObject tagSetTwo = new BasicDBObject("region", "US_West"); ReadPreference pref =ReadPreference.primaryPreferred(tagSetOne, tagSetTwo); } }
1. 错误
操作系统和数据库都是服务提供商安装的,过了几个月才想起要用这个数据库,启动时出现如下错误。
ORA-00704: bootstrap process failure