cancel
Showing results for 
Search instead for 
Did you mean: 

To access database by javabean

Former Member
0 Kudos

Hi,

I create new java program and jar it to jar file, then I import this jar file as the model.

I try this program in normal jdk, it is no problem. But when I use it as the model, I encounter the exclamation after the deployment and run.

My program is as the following.

Can't I put the connection statement in the construction ?package com.sun;

-


package com.sun;

import java.math.BigDecimal;

import java.sql.*;

public class EmpBean{

private int empno;

private String ename = "";

private String job = "";

private int mgr;

private double sal;

private double comm;

private int deptno;

private Connection conn = null;

private Statement stmt = null;

public EmpBean(){

try {

this.conn = getConnection();

this.stmt = conn.createStatement();

String sql = "SELECT * FROM user1";

ResultSet result = stmt.executeQuery(sql);

if(result.next()){

this.ename = result.getString("name");

}

} catch (SQLException e) {

this.ename="ex1";

e.printStackTrace();

}

finally {

if(stmt != null) {

try {

stmt.close();

}

catch(SQLException e) {

this.ename="ex2";

e.printStackTrace();

}

}

if(conn != null) {

try {

conn.close();

}

catch(SQLException e) {

this.ename="ex3";

e.printStackTrace();

}

}

}

}

/*

*

public EmpBean(){

try {

this.conn = getConnection();

this.stmt = conn.createStatement();

String sql = "SELECT * FROM user1";

ResultSet result = stmt.executeQuery(sql);

if(result.next()){

this.ename = result.getString("name");

}

} catch (SQLException e) {

e.printStackTrace();

}

finally {

if(stmt != null) {

try {

stmt.close();

}

catch(SQLException e) {

e.printStackTrace();

}

}

if(conn != null) {

try {

conn.close();

}

catch(SQLException e) {

e.printStackTrace();

}

}

}

}

*/

public int getEmpno() {

this.empno=23701;

return this.empno;

}

public void setEmpno(int inValue) {

inValue=23701;

empno = inValue;

}

public String getEname() {

return this.ename;

}

public void setEname(String inValue) {

if (inValue != null)

this.ename = inValue;

}

public String getJob() {

this.job="engineer";

return this.job;

}

public void setJob(String inValue) {

inValue="inValue";

if (inValue != null)

this.job = inValue;

}

public int getMgr() {

this.mgr=22;

return this.mgr;

}

public void setMgr(int inValue) {

mgr = inValue;

}

public double getSal() {

return this.sal;

}

public void setSal(double inValue) {

inValue=10000.00;

sal = inValue;

}

public double getComm() {

this.comm=5.0;

return this.comm;

}

public void setComm(double inValue) {

comm = inValue;

}

public int getDeptno() {

return this.deptno;

}

public void setDeptno(int inValue) {

deptno = inValue;

}

/* public void setAttributes(ResultSet rs)

throws SQLException {

setEmpno(rs.getInt("EMPNO"));

setEname(rs.getString("ENAME"));

setJob(rs.getString("JOB"));

setMgr(rs.getInt("MGR"));

//setHiredate(rs.getDate("HIREDATE"));

setSal(rs.getDouble("SAL"));

setComm(rs.getDouble("COMM"));

setDeptno(rs.getInt("DEPTNO"));

}

public String insertStatement() {

String str = "INSERT INTO EMP (EMPNO,ENAME,JOB,MGR,SAL,COMM,DEPTNO) VALUES (?,?,?,?,?,?,?,?)";

return str;

}

public void insertDatabase(Connection conn)

throws SQLException {

PreparedStatement ps = null;

try {

ps = conn.prepareStatement(insertStatement());

ps.setInt(1, getEmpno());

ps.setString(2, getEname());

ps.setString(3, getJob());

ps.setInt(4, getMgr());

// ps.setDate(5, getHiredate());

ps.setDouble(6, getSal());

ps.setDouble(7, getComm());

ps.setInt(8, getDeptno());

ps.executeUpdate();

} finally {

if (ps != null) {

try {

ps.close();

ps = null;

} catch(SQLException e) {}

}

}

}

*/

private static Connection getConnection() {

String DRIVER = "oracle.jdbc.OracleDriver";

String iURL = "jdbc:oracle:thin:@botstdb1:1521:dev9utf8";

String USER = "icmr2p";

String PASSWD = "icmr2p";

try {

Class.forName(DRIVER);

} catch (ClassNotFoundException e) {

System.out.println("找不到JDBC驅動程式");

e.printStackTrace();

}

Connection conn = null;

try {

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

} catch (SQLException e) {

e.printStackTrace();

}

return conn;

}

}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I found the nullpoint exception in two lines.

this.conn = getConnection();

this.stmt = conn.createStatement();

Former Member
0 Kudos

Hi,

Oh..You are getting Null pointer exception in runtime..I mean while running the application ??

In that case there could be some problem in getConnection method.

Modify the method from private to public and create the model again.

Regards,Anilkumar

Former Member
0 Kudos

Hi,

The result is the same.

You can save the following code as the html file. And you can see my result.

Thank you.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<!--

This page was created by SAP NetWeaver. All rights reserved.

Web Dynpro client:

HTML Client

Web Dynpro client capabilities:

User agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0), client type: msie6, client type profile: ie6, ActiveX: enabled, Cookies: enabled, Frames: enabled, Java applets: enabled, JavaScript: enabled, Tables: enabled, VB Script: enabled

Accessibility mode: false

Web Dynpro runtime:

Vendor: SAP, build ID: 7.0007.20060509173555.0000 (release=NW04S_07_REL, buildtime=2006-05-09:16:21:23[UTC], changelist=13857, host=pwdfm114), build date: Fri Feb 02 13:30:20 CST 2007

Web Dynpro code generators of DC local/EmpBean11:

SapDictionaryGenerationCore: 7.0007.20060210160356.0000 (release=645_VAL_REL, buildtime=2006-03-23:20:00:00[UTC], changelist=388986, host=PWDFM101.wdf.sap.corp)

SapMetamodelWebDynpro: 7.0007.20060210162212.0000 (release=645_VAL_REL, buildtime=2006-03-23:20:02:28[UTC], changelist=389002, host=PWDFM101.wdf.sap.corp)

SapMetamodelCore: 7.0007.20060210160857.0000 (release=645_VAL_REL, buildtime=2006-03-23:19:50:19[UTC], changelist=388995, host=PWDFM101.wdf.sap.corp)

SapWebDynproGenerationTemplates: 7.0007.20060316153408.0000 (release=645_VAL_REL, buildtime=2006-03-23:20:21:34[UTC], changelist=394237, host=pwdfm101)

SapWebDynproGenerationCTemplates: 7.0007.20060316153408.0000 (release=645_VAL_REL, buildtime=2006-03-23:20:21:34[UTC], changelist=394237, host=pwdfm101)

SapGenerationFrameworkCore: 7.0007.20050713144242.0000 (release=645_VAL_REL, buildtime=2006-03-23:19:49:40[UTC], changelist=357697, host=PWDFM101.wdf.sap.corp)

SapIdeWebDynproCheckLayer: 7.0007.20060228171604.0000 (release=645_VAL_REL, buildtime=2006-03-23:20:05:31[UTC], changelist=391800, host=PWDFM101.wdf.sap.corp)

SapMetamodelDictionary: 7.0007.20051128142655.0000 (release=645_VAL_REL, buildtime=2006-03-23:19:57:45[UTC], changelist=378069, host=PWDFM101.wdf.sap.corp)

SapMetamodelCommon: 7.0007.20060210160857.0000 (release=645_VAL_REL, buildtime=2006-03-23:19:50:26[UTC], changelist=388995, host=PWDFM101.wdf.sap.corp)

SapWebDynproGenerationCore: 7.0007.20060228171604.0000 (release=645_VAL_REL, buildtime=2006-03-23:20:05:46[UTC], changelist=391800, host=PWDFM101.wdf.sap.corp)

SapDictionaryGenerationTemplates: (unknown)

Web Dynpro code generators of DC sap.com/tcwddispwda: No information available!

Web Dynpro code generators of DC sap.com/tcwdcorecomp: No information available!

J2EE Engine:

Java VM:

Java HotSpot(TM) Server VM, version: 1.4.2_09-b05, vendor: Sun Microsystems Inc.

Operating system:

Windows 2000, version: 5.0, architecture: x86

-->

<html dir="ltr">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta http-equiv="imagetoolbar" content="no">

<title>App</title>

<script type="text/javascript">

SSRinitialParseStart = new Date().valueOf();

</script>

<link rel="stylesheet" type="text/css" href="../../../resources/sap.com/tcwddispwda/global/SSR/themes/sap_tradeshow/ur/ur_ie6.css">

<style type="text/css">

.hidden

</style>

<script type="text/javascript" src="../../../resources/sap.com/tcwddispwda/global/SSR/js/sapWdSsr_ie6.js"></script>

<script type="text/javascript" src="../../../resources/sap.com/tcwddispwda/global/SSR/js/sapUrMapi_ie6.js"></script>

<script type="text/javascript" src="../../../resources/sap.com/tcwddispwda/global/SSR/js/languages/urMessageBundle_zh.js"></script>

<script type="text/javascript" src=""></script>

<script type="text/javascript" src=""></script>

<script type="text/javascript" src=""></script>

<script type="text/javascript">

ur_system = ;

// Domain relaxing

var hostname = location.hostname;

if( !(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.test(hostname)) ) {

var posBehindFirstDot = hostname.indexOf( "." ) + 1;

if (posBehindFirstDot > 0) document.domain = hostname.substr(posBehindFirstDot);

}

// Create me-Reference needed for UR

me = window;

{ // Create SSR-manager instance

var urls = {

blank: "../../../resources/sap.com/tcwddispwda/global/SSR/html/blank.html",

backdummy: "../../../resources/sap.com/tcwddispwda/global/SSR/html/backdummy.html",

backprevention: "../../../resources/sap.com/tcwddispwda/global/SSR/html/backprevention.html",

relaxer: "../../../resources/sap.com/tcwddispwda/global/SSR/html/relaxer.html",

pixelgif: "../../../resources/sap.com/tcwddispwda/global/SSR/1.gif",

unload: "../../local/EmpBean11/App?sap-wd-cltwndid=74f18cf2c1aa11dbb54c00118561729b&sap-wd-appwndid=74f18cf3c1aa11dbc07800118561729b&sap-sessioncmd=unload"

}

new UCF_SSRManager(urls, "innerHTML", false);

}

// Provide shortcut functions for html event handlers

// handle(browserEvent, browserWindow, htmlRef, controlType, urEventName, parameters, path, flushQueue, mapiCall)

h_ = function(browserEvent, browserWindow) {

return SSR.handle(browserEvent, browserWindow);

}

h_e = function(browserEvent, browserWindow, htmlRef, controlType, urEventName, parameters, path, flushQueue) {

return SSR.handle(browserEvent, browserWindow, htmlRef, controlType, urEventName, parameters, path, flushQueue);

}

h_m = function(browserEvent, browserWindow, mapiCall) {

return SSR.handle(browserEvent, browserWindow, null, null, null, null, null, null, mapiCall);

}

h_em = function(browserEvent, browserWindow, htmlRef, controlType, urEventName, parameters, path, flushQueue, mapiCall) {

return SSR.handle(browserEvent, browserWindow, htmlRef, controlType, urEventName, parameters, path, flushQueue, mapiCall);

}

</script>

</head>

<body class="urBdyStd" onload="SSR.fireLoad()" onunload="SSR.fireUnload()" >

<form id="_SSR_UploadForm" method="POST" onsubmit="return false;"

target="_SSR_TransportFrame_75429320c1aa11dbbaf100118561729b" action="../../local/EmpBean11/App?SAPtestId=51&sap-wd-cltwndid=74f18cf2c1aa11dbb54c00118561729b&sap-wd-appwndid=74f18cf3c1aa11dbc07800118561729b" enctype="multipart/form-data"

style="BORDER-WIDTH: 0px; MARGIN: 0px;">

<div id="_SSR_ROOT" style="height: 0px">

<script>

sapUrMapi_init();

</script>

<div><span ct="FlowLayout" class="urFlowLayout"><span id="LEPA.EmpCompView.DefaultTextView" ct="TV" class="urTxtStd" style="white-space:nowrap;">EmpCompView</span><div><table cellspacing="0" cellpadding="0" ct="ML" class="urMatrixLayout" border="0"><tbody class="urLinStd"><tr><td valign="BASELINE" class="urLayoutDefault"><label ct="L" f="LEPA.EmpCompView.comm" class="urLBarDsbl" style="white-space:nowrap;">comm:</label></td><td valign="BASELINE" class="urLayoutDefault"><span id="LEPA.EmpCompView.comm-r" class="urEdf2Whl"><input type="Text" class="urEdf2TxtEnbl urEdf2TxtDsbl" autocomplete="off" showlength="true" id="LEPA.EmpCompView.comm" ct="I" name="LEPA.EmpCompView.comm" st="d" tp="INTEGER" readonly="true" tabindex="-1" ti="-1" value="" style="text-align:right;"><img src="../../../resources/sap.com/tcwddispwda/global/SSR/1.gif" class="urEdfMaskOn" align="absmiddle" style="width:0px;"></span></td></tr><tr><td valign="BASELINE" class="urLayoutDefault"><label ct="L" f="LEPA.EmpCompView.deptno" class="urLBarDsbl" style="white-space:nowrap;">deptno:</label></td><td valign="BASELINE" class="urLayoutDefault"><span id="LEPA.EmpCompView.deptno-r" class="urEdf2Whl"><input type="Text" class="urEdf2TxtEnbl urEdf2TxtDsbl" autocomplete="off" showlength="true" id="LEPA.EmpCompView.deptno" ct="I" name="LEPA.EmpCompView.deptno" st="d" tp="INTEGER" readonly="true" tabindex="-1" ti="-1" value="" style="text-align:right;"><img src="../../../resources/sap.com/tcwddispwda/global/SSR/1.gif" class="urEdfMaskOn" align="absmiddle" style="width:0px;"></span></td></tr><tr><td valign="BASELINE" class="urLayoutDefault"><label ct="L" f="LEPA.EmpCompView.empno" class="urLBarDsbl" style="white-space:nowrap;">empno:</label></td><td valign="BASELINE" class="urLayoutDefault"><span id="LEPA.EmpCompView.empno-r" class="urEdf2Whl"><input type="Text" class="urEdf2TxtEnbl urEdf2TxtDsbl" autocomplete="off" showlength="true" id="LEPA.EmpCompView.empno" ct="I" name="LEPA.EmpCompView.empno" st="d" tp="INTEGER" readonly="true" tabindex="-1" ti="-1" value="" style="text-align:right;"><img src="../../../resources/sap.com/tcwddispwda/global/SSR/1.gif" class="urEdfMaskOn" align="absmiddle" style="width:0px;"></span></td></tr><tr><td valign="BASELINE" class="urLayoutDefault"><label ct="L" f="LEPA.EmpCompView.ename" class="urLBarDsbl" style="white-space:nowrap;">ename:</label></td><td valign="BASELINE" class="urLayoutDefault"><span id="LEPA.EmpCompView.ename-r" class="urEdf2Whl"><input type="Text" class="urEdf2TxtEnbl urEdf2TxtDsbl" autocomplete="off" showlength="true" id="LEPA.EmpCompView.ename" ct="I" name="LEPA.EmpCompView.ename" st="d" tp="STRING" readonly="true" tabindex="-1" ti="-1" value=""><img src="../../../resources/sap.com/tcwddispwda/global/SSR/1.gif" class="urEdfMaskOn" align="absmiddle" style="width:0px;"></span></td></tr><tr><td valign="BASELINE" class="urLayoutDefault"><label ct="L" f="LEPA.EmpCompView.job" class="urLBarDsbl" style="white-space:nowrap;">job:</label></td><td valign="BASELINE" class="urLayoutDefault"><span id="LEPA.EmpCompView.job-r" class="urEdf2Whl"><input type="Text" class="urEdf2TxtEnbl urEdf2TxtDsbl" autocomplete="off" showlength="true" id="LEPA.EmpCompView.job" ct="I" name="LEPA.EmpCompView.job" st="d" tp="STRING" readonly="true" tabindex="-1" ti="-1" value=""><img src="../../../resources/sap.com/tcwddispwda/global/SSR/1.gif" class="urEdfMaskOn" align="absmiddle" style="width:0px;"></span></td></tr><tr><td valign="BASELINE" class="urLayoutDefault"><label ct="L" f="LEPA.EmpCompView.mgr" class="urLBarDsbl" style="white-space:nowrap;">mgr:</label></td><td valign="BASELINE" class="urLayoutDefault"><span id="LEPA.EmpCompView.mgr-r" class="urEdf2Whl"><input type="Text" class="urEdf2TxtEnbl urEdf2TxtDsbl" autocomplete="off" showlength="true" id="LEPA.EmpCompView.mgr" ct="I" name="LEPA.EmpCompView.mgr" st="d" tp="INTEGER" readonly="true" tabindex="-1" ti="-1" value="" style="text-align:right;"><img src="../../../resources/sap.com/tcwddispwda/global/SSR/1.gif" class="urEdfMaskOn" align="absmiddle" style="width:0px;"></span></td></tr><tr><td valign="BASELINE" class="urLayoutDefault"><label ct="L" f="LEPA.EmpCompView.sal" class="urLBarDsbl" style="white-space:nowrap;">sal:</label></td><td valign="BASELINE" class="urLayoutDefault"><span id="LEPA.EmpCompView.sal-r" class="urEdf2Whl"><input type="Text" class="urEdf2TxtEnbl urEdf2TxtDsbl" autocomplete="off" showlength="true" id="LEPA.EmpCompView.sal" ct="I" name="LEPA.EmpCompView.sal" st="d" tp="INTEGER" readonly="true" tabindex="-1" ti="-1" value="" style="text-align:right;"><img src="../../../resources/sap.com/tcwddispwda/global/SSR/1.gif" class="urEdfMaskOn" align="absmiddle" style="width:0px;"></span></td></tr></table></div></span></div><div tabindex="0" ti="0" t="" st="b" class="urMsgBarErr" id="WD_MessageArea" ct="MB"><table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td class="urTxtStd" valign="top"><span id="WD_MessageArea-img" class="urMsgBarImgError"><img width="12" height="12" src="../../../resources/sap.com/tcwddispwda/global/SSR/1.gif"></span></td><td><span id="WD_MessageArea-txt" class="urTxtStd"></span></td></tr></table></div>

<div id="_SSR_ScriptAfterHTML"><!--

SSR.setDirtyMode(0);SSR.setApplicationIsDirty(false);

SSR.times.backend = 0; SSR.times.J2ee = 581;

--></div>

</div>

<input type="HIDDEN" name="sap-wd-cltwndid" value="74f18cf2c1aa11dbb54c00118561729b"/>

<input type="HIDDEN" name="sap-wd-appwndid" value="74f18cf3c1aa11dbc07800118561729b"/>

<input type="HIDDEN" name="sap-wd-norefresh" value="X"/>

<input type="HIDDEN" name="eventQueue" value=""/>

</form>

<iframe id="_SSR_BackPrevention" class="hidden" frameborder=0

tabIndex=-1 src="../../../resources/sap.com/tcwddispwda/global/SSR/html/blank.html"></iframe>

<iframe id="_SSR_TransportFrame" name="_SSR_TransportFrame_75429320c1aa11dbbaf100118561729b"

onload="return SSR.onResponse(event)" class="hidden"

frameborder=0 tabIndex=-1 src="../../../resources/sap.com/tcwddispwda/global/SSR/html/blank.html"></iframe>

<form id="_SSR_TransportForm" method="POST" target="_SSR_TransportFrame_75429320c1aa11dbbaf100118561729b"

action="../../local/EmpBean11/App?SAPtestId=51&sap-wd-cltwndid=74f18cf2c1aa11dbb54c00118561729b&sap-wd-appwndid=74f18cf3c1aa11dbc07800118561729b" class="hidden">

<input type="HIDDEN" name="sap-wd-cltwndid" value="74f18cf2c1aa11dbb54c00118561729b"/>

<input type="HIDDEN" name="sap-wd-appwndid" value="74f18cf3c1aa11dbc07800118561729b"/>

<input type="HIDDEN" name="sap-wd-norefresh" value="X"/>

<input type="HIDDEN" name="eventQueue" value=""/>

</form>

<div id="ur-loading" ct="LA" style="position:absolute;left:0;top:-5000;width:150;display:block;"><div class="urLoadA"><div class="urLoadImg"></div></div></div>

<script>

sapUrMapi_Focus_RegisterCreate('');

if (SSR.showInfo){

var browserTime = new Date().valueOf() - window._SSR_initialParseStart;

window.status = "Browser:" + browserTime + " J2EE: " + SSR.times.J2ee + " Back-End: " + SSR.times.backend;

}

</script>

<script type="text/javascript" src="../../../resources/sap.com/tcwddispwda/global/SSR/js/popup_ie6.js"></script>

</body>

</html>

Former Member
0 Kudos

I feel this stack trace nothing to do with your Bean !!!

Are you able to generate & run other WebDynpro apps ?? Check the IDE and Engine versions once.

Regards,Anilkumar

Former Member
0 Kudos

Hi,

I feel Exclamation is just a warning...Are you getting any exceptions ??

If so post the exception.

Regards,Anilkumar