当前位置: 技术问答>java相关
有谁玩过sun的JavaPetShop(一个J2EE的例子),希望有人答我。
来源: 互联网 发布时间:2015-01-08
本文导语: 下载地址http://java.sun.com/j2ee/download.html#blueprints 在linux上安装后: ============================================================ 配置文件如下: ============================================================ linux:/usr/local/j2sdkee1.2.1/config # more default...
下载地址http://java.sun.com/j2ee/download.html#blueprints
在linux上安装后:
============================================================
配置文件如下:
============================================================
linux:/usr/local/j2sdkee1.2.1/config # more default.properties
# JDBC Driver Examples:
# Oracle thin driver: oracle.jdbc.driver.OracleDriver
# Merant driver: intersolv.jdbc.sequelink.SequeLinkDriver
# Cloudscape driver: COM.cloudscape.core.RmiJdbcDriver
#
jdbc.drivers=COM.cloudscape.core.RmiJdbcDriver
# JDBC URL Examples:
# Oracle thin driver:
# jdbc:oracle:thin:@::
# Cloudscape RMI driver:
# jdbc:cloudscape:rmi:;create=true
# Merant driver:
# jdbc:sequelink://:/[SQLServer];Database=
#
#jdbc.datasources=jdbc/Cloudscape|jdbc:cloudscape:rmi:CloudscapeDB;create=true
jdbc.datasources=jdbc/Cloudscape|jdbc:cloudscape:rmi:CloudscapeDB;create=true|jdbc/MusicStoreDB|jdbc
:cloudscape:rmi:MusicStoreDB;create=false|jdbc/EstoreDB|jdbc:cloudscape:rmi:CloudscapeDB;create=true
|jdbc/InventoryDB|jdbc:cloudscape:rmi:CloudscapeDB;create=true
passivation.threshold.memory=128000000
idle.resource.threshold=600
user.transaction.jndiname=java:comp/UserTransaction
log.directory=logs
log.output.file=output.log
log.error.file=error.log
log.event.file=event.log
distributed.transaction.recovery=false
transaction.timeout=0
sessionbean.timeout=0
#
# DataSource configuration for JDBC 2.0 XA drivers only
#
#jdbc20.datasources=jdbc/Merant|jdbc/XAMerant
#xadatasource.0.jndiname=jdbc/XAMerant
#xadatasource.0.classname=com.merant.sequelink.jdbcx.datasource.SequeLinkDataSource
#xadatasource.0.dbuser=
#xadatasource.0.dbpassword=
#xadatasource.0.prop.url=jdbc:sequelink://:/[Oracle]
#
============================
启动如下:
============================
/usr/local/j2sdkee1.2.1/bin # ./cloudscape -start
Thu Jun 14 01:19:30 CST 2001: [RmiJdbc] COM.cloudscape.core.JDBCDriver registered in DriverManager
Thu Jun 14 01:19:30 CST 2001: [RmiJdbc] Binding RmiJdbcServer...
Thu Jun 14 01:19:30 CST 2001: [RmiJdbc] No installation of RMI Security Manager...
Thu Jun 14 01:19:31 CST 2001: [RmiJdbc] RmiJdbcServer bound in rmi registry
============================
:/usr/local/j2sdkee1.2.1/bin #
J2EE server Listen Port: = 1049
Naming service started: :1050
Published the configuration object ...
Binding DataSource, name = jdbc/Cloudscape, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
Binding DataSource, name = jdbc/MusicStoreDB, url = jdbc:cloudscape:rmi:MusicStoreDB;create=false
Binding DataSource, name = jdbc/EstoreDB, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
Binding DataSource, name = jdbc/InventoryDB, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
Web service started: 9191
Web service started: 8000
Web service started: 7000
J2EE server startup complete.
=========================================
测试文件如下:
/**** MusicCDInsertRecords.java ****/
import java.sql.*;
public class MusicCDInsertRecords {
public static void main(String[] args) {
if (usageOnly(args))
return;
String driver = "COM.cloudscape.core.JDBCDriver";
if (args.length > 0)
driver = args[0];
//String url = "jdbc:cloudscape:MusicStoreDB";
String url = "jdbc:cloudscape:CloudscapeDB";
System.out.println("URL:"+url);
if (args.length > 1)
url = args[1];
try {
Class.forName(driver).newInstance();
System.out.println("Driver OK!");
Connection con = DriverManager.getConnection(url);
System.out.println("Connected to: " + url);
Statement stmt = con.createStatement();
stmt.executeUpdate("insert into MUSICCD values ('74646732120', 'Retrospective', 'Rosanne Cash', 'Country', 13.95)");
stmt.executeUpdate("insert into MUSICCD values ('731454058728', 'Sheryl Crow', 'Sheryl Crow', 'Rock', 13.95)");
stmt.executeUpdate("insert into MUSICCD values ('77778929727', 'Common Ground', 'Everette Harp', 'Jazz', 13.95)");
stmt.executeUpdate("insert into MUSICCD values ('8811163020', 'Piel de Angel', 'Lucero', 'Latin', 13.95)");
stmt.executeUpdate("insert into MUSICCD values ('706301572627', 'Las Cosas Que Vives', 'Laura Pausini', 'Latin', 13.95)");
stmt.close();
con.close();
}
catch (SQLException ex) {
System.out.println("nSQLException...n");
while (ex != null) {
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("Message: " + ex.getMessage());
System.out.println("Vendor: " + ex.getErrorCode());
ex = ex.getNextException();
System.out.println("");
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private static boolean usageOnly(String[] args) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("-help") ||
args[0].equalsIgnoreCase("-h") ||
args[0].equalsIgnoreCase("-usage") ||
args.length > 2)
System.out.println(
"Usage: java MusicCDInsertRecords" +
" [] []");
return true;
}
else
return false;
}
} // MusicCDInsertRecords class //
=========================================
出现错误如下:如何才能访问数据库,URL是怎样配置的?
=========================================
/usr/local/j2sdkee1.2.1/bin # java -classpath $CLASSPATH:/usr/local/j2sdkee1.2.1/lib/cloud
scape/cloudscape.jar:/usr/local/j2sdkee1.2.1/lib/classes MusicCDInsertRecords
URL:jdbc:cloudscape:CloudscapeDB
Driver OK!
SQLException...
SQLState: XJ004
Message: Database 'CloudscapeDB' not found.
Vendor: 40000
在linux上安装后:
============================================================
配置文件如下:
============================================================
linux:/usr/local/j2sdkee1.2.1/config # more default.properties
# JDBC Driver Examples:
# Oracle thin driver: oracle.jdbc.driver.OracleDriver
# Merant driver: intersolv.jdbc.sequelink.SequeLinkDriver
# Cloudscape driver: COM.cloudscape.core.RmiJdbcDriver
#
jdbc.drivers=COM.cloudscape.core.RmiJdbcDriver
# JDBC URL Examples:
# Oracle thin driver:
# jdbc:oracle:thin:@::
# Cloudscape RMI driver:
# jdbc:cloudscape:rmi:;create=true
# Merant driver:
# jdbc:sequelink://:/[SQLServer];Database=
#
#jdbc.datasources=jdbc/Cloudscape|jdbc:cloudscape:rmi:CloudscapeDB;create=true
jdbc.datasources=jdbc/Cloudscape|jdbc:cloudscape:rmi:CloudscapeDB;create=true|jdbc/MusicStoreDB|jdbc
:cloudscape:rmi:MusicStoreDB;create=false|jdbc/EstoreDB|jdbc:cloudscape:rmi:CloudscapeDB;create=true
|jdbc/InventoryDB|jdbc:cloudscape:rmi:CloudscapeDB;create=true
passivation.threshold.memory=128000000
idle.resource.threshold=600
user.transaction.jndiname=java:comp/UserTransaction
log.directory=logs
log.output.file=output.log
log.error.file=error.log
log.event.file=event.log
distributed.transaction.recovery=false
transaction.timeout=0
sessionbean.timeout=0
#
# DataSource configuration for JDBC 2.0 XA drivers only
#
#jdbc20.datasources=jdbc/Merant|jdbc/XAMerant
#xadatasource.0.jndiname=jdbc/XAMerant
#xadatasource.0.classname=com.merant.sequelink.jdbcx.datasource.SequeLinkDataSource
#xadatasource.0.dbuser=
#xadatasource.0.dbpassword=
#xadatasource.0.prop.url=jdbc:sequelink://:/[Oracle]
#
============================
启动如下:
============================
/usr/local/j2sdkee1.2.1/bin # ./cloudscape -start
Thu Jun 14 01:19:30 CST 2001: [RmiJdbc] COM.cloudscape.core.JDBCDriver registered in DriverManager
Thu Jun 14 01:19:30 CST 2001: [RmiJdbc] Binding RmiJdbcServer...
Thu Jun 14 01:19:30 CST 2001: [RmiJdbc] No installation of RMI Security Manager...
Thu Jun 14 01:19:31 CST 2001: [RmiJdbc] RmiJdbcServer bound in rmi registry
============================
:/usr/local/j2sdkee1.2.1/bin #
J2EE server Listen Port: = 1049
Naming service started: :1050
Published the configuration object ...
Binding DataSource, name = jdbc/Cloudscape, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
Binding DataSource, name = jdbc/MusicStoreDB, url = jdbc:cloudscape:rmi:MusicStoreDB;create=false
Binding DataSource, name = jdbc/EstoreDB, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
Binding DataSource, name = jdbc/InventoryDB, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
Web service started: 9191
Web service started: 8000
Web service started: 7000
J2EE server startup complete.
=========================================
测试文件如下:
/**** MusicCDInsertRecords.java ****/
import java.sql.*;
public class MusicCDInsertRecords {
public static void main(String[] args) {
if (usageOnly(args))
return;
String driver = "COM.cloudscape.core.JDBCDriver";
if (args.length > 0)
driver = args[0];
//String url = "jdbc:cloudscape:MusicStoreDB";
String url = "jdbc:cloudscape:CloudscapeDB";
System.out.println("URL:"+url);
if (args.length > 1)
url = args[1];
try {
Class.forName(driver).newInstance();
System.out.println("Driver OK!");
Connection con = DriverManager.getConnection(url);
System.out.println("Connected to: " + url);
Statement stmt = con.createStatement();
stmt.executeUpdate("insert into MUSICCD values ('74646732120', 'Retrospective', 'Rosanne Cash', 'Country', 13.95)");
stmt.executeUpdate("insert into MUSICCD values ('731454058728', 'Sheryl Crow', 'Sheryl Crow', 'Rock', 13.95)");
stmt.executeUpdate("insert into MUSICCD values ('77778929727', 'Common Ground', 'Everette Harp', 'Jazz', 13.95)");
stmt.executeUpdate("insert into MUSICCD values ('8811163020', 'Piel de Angel', 'Lucero', 'Latin', 13.95)");
stmt.executeUpdate("insert into MUSICCD values ('706301572627', 'Las Cosas Que Vives', 'Laura Pausini', 'Latin', 13.95)");
stmt.close();
con.close();
}
catch (SQLException ex) {
System.out.println("nSQLException...n");
while (ex != null) {
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("Message: " + ex.getMessage());
System.out.println("Vendor: " + ex.getErrorCode());
ex = ex.getNextException();
System.out.println("");
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private static boolean usageOnly(String[] args) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("-help") ||
args[0].equalsIgnoreCase("-h") ||
args[0].equalsIgnoreCase("-usage") ||
args.length > 2)
System.out.println(
"Usage: java MusicCDInsertRecords" +
" [] []");
return true;
}
else
return false;
}
} // MusicCDInsertRecords class //
=========================================
出现错误如下:如何才能访问数据库,URL是怎样配置的?
=========================================
/usr/local/j2sdkee1.2.1/bin # java -classpath $CLASSPATH:/usr/local/j2sdkee1.2.1/lib/cloud
scape/cloudscape.jar:/usr/local/j2sdkee1.2.1/lib/classes MusicCDInsertRecords
URL:jdbc:cloudscape:CloudscapeDB
Driver OK!
SQLException...
SQLState: XJ004
Message: Database 'CloudscapeDB' not found.
Vendor: 40000
|
回声 ...
|
我要,呵呵。
可不可以详细描述一下Coudscape数据库什么不行,Oracle数据库为什么行,错误是什么方面的。我个人觉得这个Cloudscape好象还挺好用的呀。
可不可以详细描述一下Coudscape数据库什么不行,Oracle数据库为什么行,错误是什么方面的。我个人觉得这个Cloudscape好象还挺好用的呀。