当前位置: 技术问答>java相关
哪位能帮写个连接Oracle的JavaBean???
来源: 互联网 发布时间:2015-10-20
本文导语: 另外: Hello.java =============== package example; public class Hello { public String name = "Every one!"; public String output() { return "Hello " + name; } } hello.jsp ================ Test Bean 放在TOMCAT里webappsROOTWEB-INFclassesexa...
另外:
Hello.java
===============
package example;
public class Hello {
public String name = "Every one!";
public String output() {
return "Hello " + name;
}
}
hello.jsp
================
Test Bean
放在TOMCAT里webappsROOTWEB-INFclassesexample下一切正常,
但我新建个虚拟目录,把Hello.java放到
D:testWEB-INFclassesexample下,hello.jsp放到D:test下却不好使了,
不过其他测试虚拟目录访问正常,这是什么原因??
Hello.java
===============
package example;
public class Hello {
public String name = "Every one!";
public String output() {
return "Hello " + name;
}
}
hello.jsp
================
Test Bean
放在TOMCAT里webappsROOTWEB-INFclassesexample下一切正常,
但我新建个虚拟目录,把Hello.java放到
D:testWEB-INFclassesexample下,hello.jsp放到D:test下却不好使了,
不过其他测试虚拟目录访问正常,这是什么原因??
|
连接前须配置classpath如下:
[oracle_home]d:oracleora81jdbclibclasses111.zip;
d:oracleora81jdbclibnls_charset11.zip;
d:oracleora81jdbclibnls_charset12.zip;
d:oracleora81jdbclibclasses12.zip;
/*
* This sample shows how to list all the names from the EMP table
*
* It uses the JDBC THIN driver. See the same program in the
* oci8 samples directory to see how to use the other drivers.
*/
// You need to import the java.sql package to use JDBC
import java.sql.*;
class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as ::. The example uses the short cut syntax.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@zhang-xjing:1521:itfuture",
"scott", "tiger");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from member");
// Iterate through the result and print the employee names
while (rset.next ()){
System.out.println (rset.getString (1));
System.out.print (rset.getString (2));
System.out.print (rset.getString (3));
System.out.print (rset.getString (4));
System.out.print (rset.getString (5));
System.out.print (rset.getString (6));
System.out.print (rset.getString (7));
}
}
}
第二个问题
在test目录下没有路径example,jsp找不到bean,因为bean在example包中
(package example;)
[oracle_home]d:oracleora81jdbclibclasses111.zip;
d:oracleora81jdbclibnls_charset11.zip;
d:oracleora81jdbclibnls_charset12.zip;
d:oracleora81jdbclibclasses12.zip;
/*
* This sample shows how to list all the names from the EMP table
*
* It uses the JDBC THIN driver. See the same program in the
* oci8 samples directory to see how to use the other drivers.
*/
// You need to import the java.sql package to use JDBC
import java.sql.*;
class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as ::. The example uses the short cut syntax.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@zhang-xjing:1521:itfuture",
"scott", "tiger");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from member");
// Iterate through the result and print the employee names
while (rset.next ()){
System.out.println (rset.getString (1));
System.out.print (rset.getString (2));
System.out.print (rset.getString (3));
System.out.print (rset.getString (4));
System.out.print (rset.getString (5));
System.out.print (rset.getString (6));
System.out.print (rset.getString (7));
}
}
}
第二个问题
在test目录下没有路径example,jsp找不到bean,因为bean在example包中
(package example;)
|
上面D;testWEB-INFclassesexampleHello.java对
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。