Home » Developer & Programmer » JDeveloper, Java & XML » method not give me right result how pass code from applet to class
method not give me right result how pass code from applet to class [message #212855] Mon, 08 January 2007 10:22 Go to next message
mfa786
Messages: 210
Registered: February 2006
Location: karachi
Senior Member
hi master


sir my meed is i pass code from appletd and call class method that return me title as per code
i am use this code

""method not give me right result how pass code from applet to class""


===================
sir see my code in java class

public String mfa3(String s){
String mfatt ="lkjldsf";
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@fahim:1521:aamir","muhammad","mfa786");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select title,accid from chartofacc where accid=s");
while (rset.next())
mfatt= rset.getString("accid");
}
catch(Exception e){
e.printStackTrace();
}
return mfatt;
}


==================

and this is in applet


private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// Add your handling code here:
jTextField5.setText(testcall.mfa3((String)jTextField2.getText()));
}


when i press button then give me this error


object created
java.security.AccessControlException: access denied (java.util.PropertyPermission oracle.jserver.version read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1276)
at java.lang.System.getProperty(System.java:573)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at testclass.mfa3(testclass.java:57)
at testapp.jButton5ActionPerformed(testapp.java:114)
at testapp.access$400(testapp.java:11)
at testapp$5.actionPerformed(testapp.java:98)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)



system not give me result


sir please give me idea

thaning you

aamir
Re: method not give me right result how pass code from applet to class [message #212858 is a reply to message #212855] Mon, 08 January 2007 10:26 Go to previous messageGo to next message
kmmfoo
Messages: 38
Registered: June 2005
Location: massachusetts
Member
You are not putting the string variable "s" into the query. Try something like this:

String query = "select title,accid from chartofacc where accid="+
"'" + s.replaceAll("\\'", "\\'\\'") + "'";
ResultSet rset = stmt.executeQuery(query);

HTH...
Re: method not give me right result how pass code from applet to class [message #212959 is a reply to message #212858] Mon, 08 January 2007 23:02 Go to previous messageGo to next message
mfa786
Messages: 210
Registered: February 2006
Location: karachi
Senior Member
thank for your reply

sir if i have more then one condition such as

accid , date, nicno, salary

then what i use in query

please give me idea

thank you

aamir
Re: method not give me right result how pass code from applet to class [message #213094 is a reply to message #212959] Tue, 09 January 2007 08:23 Go to previous message
kmmfoo
Messages: 38
Registered: June 2005
Location: massachusetts
Member
The idea is that you want the variable "query" to be a string that contains a correctly-formatted sql query, right? so if you had four or five different variables to put into the query, you would just build that string.

Let's take it in steps.

Step 1, assume it's just a string. To put a string into a query, you would surround it with single quotes, right? So for example, if you had a variable "s" that contained a string, you would add it to a query like this:

query = "select title,accid from chartofacc where accid='" +
s + "'";

Do you see what that is doing?

Step 2, do you see the problem with that previous example? The problem is, if the string inside variable "s" contains a single-quote character, it would create a malformed query.

For example, assume it contained the string "don't do this". The query would look like

select title,accid from chartofacc where accid='don't do this'

which is a bad query. So if we want to fix that problem, we would have to double any single-quote characters inside our strings. That is usually done with the regex function "String.replaceAll()", as in my example.

However, it gets very complicated to do that all the time, so what many people do is to create a local private function to do that replacement, and call the local private function.

But even that approach becomes tedious, which is why Java contains a "PreparedStatement" method, which does all of this for you. If you are interested you could look that up in the documentation.

Hope this helps.





Previous Topic: how send table data to applet from java class
Next Topic: applet give me error (java.security.AccessControlException: access denied (java.util.PropertyPermiss
Goto Forum:
  


Current Time: Mon Dec 05 14:54:08 CST 2016

Total time taken to generate the page: 0.07870 seconds