cancel
Showing results for 
Search instead for 
Did you mean: 

Read MYSQL with WebDynpro

Former Member
0 Kudos

Hello Experts,

i want to read data from a mySQL Database with WebDynpro. If i write a java programm to do this it works perfectly, but if I use this Java code in my WebDynpro Application it doesn't work.

So how can I run this code in my WebDynpro-project:

String Query = null;

java.sql.Connection con = null;

java.sql.Statement stmt = null;

ResultSet rs = null;

try {

Class.forName("com.mysql.jdbc.Driver");

}

catch (ClassNotFoundException e) {

e.printStackTrace();

System.exit(1);

}

System.out.println(time.toString());

System.out.println(time);

try {

con =

DriverManager.getConnection(

"jdbc:mysql://server.com",

"user",

"password");

stmt = con.createStatement();

rs = stmt.executeQuery("USE database");

rs = stmt.executeQuery("SELECT * FROM table");

while (rs.next()) {

System.out.print(rs.getString(6));

System.out.print(" --- " + rs.getString(7));

System.out.print(" --- " + rs.getString(8));

System.out.println(" --- " + rs.getString(9));

}

con.close();

rs.close();

stmt.close();

}

catch (SQLException e5) {

e5.printStackTrace();

}

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

I think the problem is:

I don't have installed the mysql driver on the portal... so how can I do this?

Or how can i check this?

thanks!

Former Member
0 Kudos

/thread/41500 [original link is broken]

Former Member
0 Kudos

You have to access Visual Admin, then choose JDBC Connector -> Drivers, then load the Driver (jar file).

Restart AS Stack Java and then you can create all DataSources you need.

Hope this help.

Vi.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hello,

I can deploy the application successful, but when it is deployed the server crashes down. I think the problem ist the mySQL Connector on wich I refer: Class.forName("com.mysql.jdbc.Driver");

On my local machine the driver is installed but in the Portal he isn't installed.

Thanks for your answers!

Former Member
0 Kudos

So how can i get this mysql driver work?

Former Member
0 Kudos

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

}

catch (Exception exc) {

System.err.println("Exception in init(): Unable to load JDBC driver");

exc.printStackTrace();

}

try {

conn = DriverManager.getConnection("jdbc:mysql://localhost/" + DBNAME);

/thread/41500 [original link is broken]

Former Member
0 Kudos

I got this exception:

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

Former Member
0 Kudos

go thru dis blog

it will b helpful n will solve ur prob

/people/venkatesh.ramachandran/blog/2006/10/19/how-to-create-and-remove-data-source-on-sap-was-j2ee-engine-dynamically-through-java

JDBCDescriptor jdbcDescriptor = new JDBCDescriptor();

jdbcDescriptor.setDataSourceName("ds_venky");

jdbcDescriptor.setDriverClassName("org.gjt.mm.mysql.Driver");

jdbcDescriptor.setDriverName("mysql");

jdbcDescriptor.setInitConnections(2);

jdbcDescriptor.setMaxConnections(10);

jdbcDescriptor.setPassword("xxxx");

jdbcDescriptor.setURL("jdbc:mysql://172.22.76.8:3306/wise");

jdbcDescriptor.setUsername("xxxx");

Properties ctxProp = new Properties();

ctxProp.put(

Context.INITIAL_CONTEXT_FACTORY,

"com.sap.engine.services.jndi.InitialContextFactoryImpl");

ctxProp.put(Context.PROVIDER_URL, "myServerName:50004");

ctxProp.put(Context.SECURITY_PRINCIPAL, "xxxx");

ctxProp.put(Context.SECURITY_CREDENTIALS, "xxxx");

InitialContext context = new InitialContext(ctxProp);

DataSourceManager dsm =

(DataSourceManager) context.lookup("dbpool");

dsm.createDataSource("ds_venky", jdbcDescriptor);

Former Member
0 Kudos

Hi Johannes,

what type of exception do you have? Hovewer, a detailed documentation on "Using JDBC with MySQL" is here:

http://www.developer.com/java/data/article.php/3417381

Hope this help you.

Regards,

Vito

Former Member
0 Kudos

HI johannes,

Web dynpro application should follow some coding rules,

The following lines are not accepted by web dynpro

you first go through the web dynpro documentaions

e.printStackTrace();

System.exit(1);

System.out.println(time.toString());

System.out.println(time);

System.out.print(rs.getString(6));

System.out.print(" --- " + rs.getString(7));

System.out.print(" --- " + rs.getString(8));

System.out.println(" --- " + rs.getString(9));

e5.printStackTrace();

in webdynpro replace following

system.out.println()----


>wdComponentAPI.getMessageManager().reportSuccess()

To start with WD Java, the following tutorial wil be helpfiul

http://help.sap.com/saphelp_nw04/helpdata/en/f8/bdfe80d9a3b048a5fb32a7d149774e/frameset.htm

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/49f2ea90-0201-0010-ce8e-de18b94a...

To know about Web Dynpro UI Element Reference Guide

http://help.sap.com/saphelp_nw04/helpdata/en/5c/1b76bc3da0504e8b535cf3e154eaa7/frameset.htm

please go to following url,

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/49f2ea90-0201-0010-ce8e-de18b94a...

there is lot of basic tutorials is there. please go throught it

Refer these links

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/web%20dynpro...

What is Web Dynpro?

Why WebDynpro ?

Why webdynpro and not BSP or JSP?

BSP to WEB Dynpro

Benifits of using Webdynpro

WEbDynpro Java vs. WebDynpro ABAP

regarding Java related webdynpro

Web Dynpro vs. Struts - a few questions

What kind of applications are being developed with Web Dynpro?

Check this:

http://www.sappro.com/downloads/OptionComparison.pdf

Refer these links

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/web%20dynpro...

regarding Java related webdynpro

Regards,

P.Manivannan