package testjdbc;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class test {
private static Context getInitialContext() throws Exception {
String url = "t3://theone:7001";
String user = "system";
String password = "systemboot";
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS,
password == null ? "" : password);
} return new InitialContext(properties);
}
catch (Exception e) {
throw e;
}
}
public static void main(String[] args) {
DataSource ds=null;
Context ctx=null;
Connection myConn = null; try{
ctx = getInitialContext();
ds = (DataSource)ctx.lookup("myJDataSource");
}
catch(Exception E){
System.out.println("Init Error:"+E);
} Statement myStatement = null;
ResultSet myResultSet = null; try{ myConn = ds.getConnection();
myStatement = myConn.createStatement();
myResultSet = myStatement.executeQuery("SELECT full_name FROM employee"); while(myResultSet.next())
{
System.out.println("the empolyee full name is"+myResultSet.getString("full_name"));
}
myResultSet.close();
}
catch(SQLException e){
System.out.println("Error code ="+ e.getErrorCode());
System.out.println("Error Messgege =" + e.getMessage());
}
finally{
try {
if (myStatement != null) {
myStatement.close();
}
if (myConn != null) {
myConn.close();
}
}
catch (SQLException e) {
System.out.println("Error code =" + e.getErrorCode());
System.out.println("Error Messgege =" + e.getMessage());
} }
}}
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class test {
private static Context getInitialContext() throws Exception {
String url = "t3://theone:7001";
String user = "system";
String password = "systemboot";
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS,
password == null ? "" : password);
} return new InitialContext(properties);
}
catch (Exception e) {
throw e;
}
}
public static void main(String[] args) {
DataSource ds=null;
Context ctx=null;
Connection myConn = null; try{
ctx = getInitialContext();
ds = (DataSource)ctx.lookup("myJDataSource");
}
catch(Exception E){
System.out.println("Init Error:"+E);
} Statement myStatement = null;
ResultSet myResultSet = null; try{ myConn = ds.getConnection();
myStatement = myConn.createStatement();
myResultSet = myStatement.executeQuery("SELECT full_name FROM employee"); while(myResultSet.next())
{
System.out.println("the empolyee full name is"+myResultSet.getString("full_name"));
}
myResultSet.close();
}
catch(SQLException e){
System.out.println("Error code ="+ e.getErrorCode());
System.out.println("Error Messgege =" + e.getMessage());
}
finally{
try {
if (myStatement != null) {
myStatement.close();
}
if (myConn != null) {
myConn.close();
}
}
catch (SQLException e) {
System.out.println("Error code =" + e.getErrorCode());
System.out.println("Error Messgege =" + e.getMessage());
} }
}}
解决方案 »
- 请教一个spring声明式事务管理问题
- Eclipse开发struts2,Tomcat启动出错
- struts1.2+hibernate+spring整合的异常处理相关问题
- NoSuchMethodException
- 关于session的线程安全以及自己做购物车例子时遇到的一些技术问题~帮忙~3Q在线等!:P
- 求救:关于jdbc 存取 oracle clob 的问题?
- 怎样将XML文件导入到ORACLE数据库中,谢谢了。。。
- JBuilder7与weblogic6.1的配置问题!不支持javabean与servlet
- 这么常见的问题为什么没人回答?(EJB--分布式数据库)
- 这是Why?
- 不知128M内存能不能运行weblogic server?
- 今天考试用JBuilder8遇到些问题?
c:\jdbc java -classpath c:\jdbc testjdbc.test
不过你要先编译,编译就不用我教你了吧。