如果它在我的weblogic服务器或我的代码中,我不知道我的错误。 任何人都可以解释我的错误日志。
public class Type4Conn{
public static void main(String ar[])throws Exception{
String username="SYSTEM";
String password="system";
// java.sql.Driver myDriver = (java.sql.Driver)
// Class.forName("weblogic.jdbc.rmi.Driver").newInstance();
// String url = "jdbc:weblogic:rmi";
// java.util.Properties props = new java.util.Properties();
// props.put("weblogic.server.url", "t3://hostname:port");
// props.put("weblogic.jdbc.datasource", "myDataSource");
// java.sql.Connection conn = myDriver.connect(url, props);
//Class.forName("weblogic.jndi.rmi.Driver").newInstance();
Properties p=new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://http://192.168.1.188:7001");
p.put(Context.SECURITY_PRINCIPAL, username);
p.put(Context.SECURITY_CREDENTIALS, password);
InitialContext ctx=new InitialContext(p);
DataSource ds=(DataSource)ctx.lookup("ds_orclmrcos"); // "java:ds_orclmrcos" java:comp/env/persistence/
Connection con=ds.getConnection();
Statement st=con.createStatement();
st.executeUpdate("insert into TBL_CUSTOMER(CUST_ID, CUST_FNAME, CUST_MNAME, CUST_LNAME,CUST_ADDRESS,CUST_STATUS)"+
"VALUES('C-002', 'ALVIN', 'C.','TEST','MANILA', 'PERMANENT')");
// int a=st.executeUpdate("insert into TBL_ values('test','testuser',2)");
System.out.println(" records inserted");
这是我的代码。我无法理解我的错误。我是网络逻辑的新手..
这是我的错误日志
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -16
at java.lang.String.substring(Unknown Source)
at weblogic.corba.j2ee.naming.NameParser.parseURL(NameParser.java:447)
at weblogic.corba.j2ee.naming.ORBHelper.parseURL(ORBHelper.java:678)
at weblogic.corba.j2ee.naming.ORBHelper.getORBReference(ORBHelper.java:528)
at weblogic.corba.j2ee.naming.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:85)
at weblogic.corba.j2ee.naming.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:31)
at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:46)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at com.rest.client.Type4Conn.main(Type4Conn.java:38)
答案 0 :(得分:0)
你的代码 - 删除“Context.PROVIDER_URL”中的双重协议片段。我认为应该是
"t3://192.168.1.188:7001"