我写了段代码,主要是想通过weblogic访问数据库,但是运行时出错:Could not find the main class.代码如下:请大侠们帮忙啊!
我写了段代码,主要是想通过weblogic访问数据库,但是运行时出错:Could not find the main class.代码如下:
ackage testdb;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
public class ConnDBMS {
public ConnDBMS() {
}
public static void main(String[] args){
DataSource ds = null;
Context ctx = null;
Connection MyConn = null;
try{
ctx = getInitialcontext();
ds = (javax.sql.DataSource)ctx.lookup("DataS_Mizuda") ;
}
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 * from employee");
while(myResultSet.next())
{
System.out.println("Name is:" + myResultSet.getString("EmpName"));
}
myResultSet.close();
}
catch(SQLException e){
System.out.println("Error code = " + e.getErrorCode());
System.out.println("Error message = " + 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 message = " + e.getMessage());
}
}
}
private static Context getInitialcontext() throws Exception{
String url = "T17://Localhost:7001";
String user = "tang";
String password = "12345678";
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;
}
}
}
出现编译错误:
java.lang.NoClassDefFoundError: weblogic/Server
Exception in thread "main"