cancel
Showing results for 
Search instead for 
Did you mean: 

DB Connection - Why does not the sql statement data display?

Former Member
0 Kudos

1. I config the data source MYSQL in visual admin successfylly.

2. I connect to MYSQL and select table data.

3. But all data is null.

My program is as the following.

Variable name1 is always null.

-


public static Connection getConnection() {

String DRIVER = "com.mysql.jdbc.Driver";

String iURL = "jdbc:mysql://ec004056:3306/demo";

String USER = "root";

String PASSWD = "123123";

try {

Class.forName(DRIVER);

} catch (ClassNotFoundException e) {

System.out.println("DB Driver Error");

e.printStackTrace();

}

Connection conn = null;

try {

conn = DriverManager.getConnection(iURL, USER, PASSWD);

} catch (SQLException e) {

e.printStackTrace();

}

return conn;

};

-


public void createBasket( )

{

//@@begin createBasket()

//sandy start

String name1;

name1=null;

int age;

age=30;

//String BASKET1[][]=null;

Connection conn = null;

Statement stmt = null;

ResultSet result=null;

int j=0;

try{

InitialContext ic = new InitialContext();

DataSource ds = (DataSource)ic.lookup("MYSQL");

conn=ds.getConnection();

//stmt = conn.prepareStatement("SELECT * FROM user");

//conn = getConnection();

//stmt = conn.createStatement();

String sql = "SELECT * FROM user";

result = stmt.executeQuery(sql);

//while (result.next())

//{

name1=result.getString(1);

// j++;

//}

}catch(Exception e){

e.printStackTrace();

}

//sandy end

for (int i = 0; i < BASKET.length ; i++)

{

IProductsElement product = wdContext.createProductsElement();

product.setARTICLE(name1);

product.setCOLOR(BASKET<i>[1]);

product.setCURRENCY("EUR");

product.setSIZE(BASKET<i>[2]);

product.setORDER_NUMBER(BASKET<i>[3]);

product.setPRICE(new BigDecimal(BASKET<i>[4]));

product.setSPECIAL_FEATURES(BASKET<i>[5]);

product.setTEXTILE_CATEGORY(BASKET<i>[6]);

wdContext.nodeProducts().addElement(product);

}

//@@end

}

-


public void wdDoInit()

{

//@@begin wdDoInit()

createBasket();

//@@end

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Replace the following

DataSource ds = (DataSource)ic.lookup("MYSQL");

with

DataSource ds = (DataSource)ic.lookup("jdbc/MYSQL");

Regards, Anilkumar

Former Member
0 Kudos

Hi,

This method I have tried. But the result is the same.

No any exceptions and no errors.

Answers (5)

Answers (5)

Former Member
0 Kudos

1. To add exception to watch error like the following.

-


try{

conn = getConnection();

stmt = conn.createStatement();

//stmt = conn.prepareStatement("SELECT * FROM user1");

String sql = "select * from user1";

result = stmt.executeQuery(sql);

int cnt=0;

while(result.next()){

name1[cnt]=result.getString("name");

cnt++;

}

}catch(Exception e){

wdComponentAPI.getMessageManager().reportException(e.toString(),true);

}

2. Found the database something wrong, I setup another database.

Former Member
0 Kudos

Hi

I setup another database testes connection with no error in visual admin. Then my connection is OK. Thank you.

Former Member
0 Kudos

Hi,

So your problem is solved or remains same ??

Regards, ANilkumar

Former Member
0 Kudos

Hi All,

I add exception then I got the following message.

com.sap.engine.services.dbpool.exceptions.BaseSQLException: ResourceException in method ConnectionFactoryImpl.getConnection(): com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: java.sql.SQLException: Data source rejected establishment of connection, message from server: "Host 'ec004076.tsmc' is not allowed to connect to this MySQL server"

<b>

What can I do?</b>

Former Member
0 Kudos

Hi All,

But when I execute sql statement in visual admin, the error is as the following.

java.rmi.RemoteException: com.sap.engine.services.dbpool.exceptions.BaseRemoteException: SQL statement(s) cannot be executed over DataSource "MYSQL". If you are using an Open SQL DataSource, you must register your tables using JDDI before you request them. Reason: com.sap.engine.services.dbpool.exceptions.BaseSQLException: ResourceException in method ConnectionFactoryImpl.getConnection(): com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: java.sql.SQLException: Data source rejected establishment of connection, message from server: "Host 'ec004076.tsmc' is not allowed to connect to this MySQL server" [id = Unknown]

at com.sap.engine.services.dbpool.deploy.DataSourceManagerImpl.executeFromAppThread(DataSourceManagerImpl.java:1195)

at com.sap.engine.services.dbpool.deploy.DataSourceManagerImpl.executeInitStatements(DataSourceManagerImpl.java:532)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at com.sap.pj.jmx.introspect.DefaultMBeanInvoker.invoke(DefaultMBeanInvoker.java:58)

at com.sap.pj.jmx.mbeaninfo.AdditionalInfoProviderMBean.invoke(AdditionalInfoProviderMBean.java:289)

at com.sap.pj.jmx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:944)

at com.sap.pj.jmx.server.interceptor.MBeanServerWrapperInterceptor.invoke(MBeanServerWrapperInterceptor.java:288)

at com.sap.engine.services.jmx.CompletionInterceptor.invoke(CompletionInterceptor.java:400)

at com.sap.pj.jmx.server.interceptor.BasicMBeanServerInterceptor.invoke(BasicMBeanServerInterceptor.java:277)

at com.sap.jmx.provider.ProviderInterceptor.invoke(ProviderInterceptor.java:258)

at com.sap.engine.services.jmx.RedirectInterceptor.invoke(RedirectInterceptor.java:340)

at com.sap.pj.jmx.server.interceptor.MBeanServerInterceptorChain.invoke(MBeanServerInterceptorChain.java:330)

at com.sap.engine.services.jmx.MBeanServerSecurityWrapper.invoke(MBeanServerSecurityWrapper.java:287)

at com.sap.engine.services.jmx.MBeanServerInvoker.invokeMbs(MBeanServerInvoker.java:157)

at com.sap.engine.services.jmx.ClusterInterceptor.invokeMbs(ClusterInterceptor.java:220)

at com.sap.engine.services.jmx.ClusterInterceptor.invoke(ClusterInterceptor.java:803)

at com.sap.engine.services.jmx.MBeanServerInterceptorInvoker.invokeMbs(MBeanServerInterceptorInvoker.java:102)

at com.sap.engine.services.jmx.connector.p4.P4ConnectorServerImpl.invokeMbs(P4ConnectorServerImpl.java:61)

at com.sap.engine.services.jmx.connector.p4.P4ConnectorServerImplp4_Skel.dispatch(P4ConnectorServerImplp4_Skel.java:64)

at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:304)

at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:193)

at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:122)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)

Caused by: com.sap.engine.services.dbpool.exceptions.BaseSQLException: ResourceException in method ConnectionFactoryImpl.getConnection(): com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: java.sql.SQLException: Data source rejected establishment of connection, message from server: "Host 'ec004076.tsmc' is not allowed to connect to this MySQL server"

at com.sap.engine.services.dbpool.cci.ConnectionFactoryImpl.getConnection(ConnectionFactoryImpl.java:59)

at com.sap.engine.services.dbpool.deploy.DBInitializer.run(DBInitializer.java:62)

... 4 more

Caused by: com.sap.engine.services.dbpool.exceptions.BaseResourceException: SQLException thrown by the physical connection: java.sql.SQLException: Data source rejected establishment of connection, message from server: "Host 'ec004076.tsmc' is not allowed to connect to this MySQL server"

at com.sap.engine.services.dbpool.spi.ManagedConnectionFactoryImpl.createManagedConnection(ManagedConnectionFactoryImpl.java:188)

at com.sap.engine.services.connector.jca.ConnectionHashSet.match(ConnectionHashSet.java:320)

at com.sap.engine.services.connector.jca.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:234)

at com.sap.engine.services.dbpool.cci.ConnectionFactoryImpl.getConnection(ConnectionFactoryImpl.java:51)

... 5 more

Caused by: java.sql.SQLException: Data source rejected establishment of connection, message from server: "Host 'ec004076.tsmc' is not allowed to connect to this MySQL server"

at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:645)

at com.mysql.jdbc.Connection.createNewIO(Connection.java:1771)

at com.mysql.jdbc.Connection.<init>(Connection.java:440)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:400)

at com.sap.engine.services.dbpool.spi.ManagedConnectionFactoryImpl.createManagedConnection(ManagedConnectionFactoryImpl.java:158)

... 8 more

at com.sap.engine.services.dbpool.exceptions.BaseRemoteException.writeReplace(BaseRemoteException.java:178)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at java.io.ObjectStreamClass.invokeWriteReplace(ObjectStreamClass.java:896)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1011)

at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)

at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:367)

at javax.management.MBeanException.writeObject(MBeanException.java:126)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:809)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)

at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:367)

at com.sap.exception.BaseExceptionInfo.writeObject(BaseExceptionInfo.java:964)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:809)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)

at com.sap.engine.services.jmx.ResponseMessage.writeBody(ResponseMessage.java:169)

at com.sap.engine.services.jmx.Message.writeMsg(Message.java:257)

at com.sap.engine.services.jmx.Message.getMsg(Message.java:453)

at com.sap.engine.services.jmx.Message.writeExternal(Message.java:505)

at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1267)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1245)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)

at com.sap.engine.services.jmx.connector.p4.P4ConnectorServerImplp4_Skel.dispatch(P4ConnectorServerImplp4_Skel.java:66)

at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:304)

at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:193)

at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:122)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)

Former Member
0 Kudos

Change the Datasource type to NativeSQL in the JDBC Sources.

Regards, ANilkumar

Former Member
0 Kudos

Hi,

Why did you commented the while (rs.next()) loop ??

Uncomment and try.

Do you see any exception in that method ??

Regards,Anilkumar

Former Member
0 Kudos

Dear sir,

No any exceptions.

Former Member
0 Kudos

Hi,

I just let program easy.