the post at: -
http://groups.google.com/group/oop_programming/browse_thread/thread/f2df17c480e45369
thanks....
Pradyut
http://pradyut.tk
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://www.flickr.com/photos/praddy
http://groups.google.com/group/oop_programming
India
Thursday, March 12, 2009
Saturday, November 29, 2008
java resultset using mysql stored procedure
Obtaining a java sql resultset using mysql stored procedure is quite a headache....
any better implementation is always a welcome....
I have used "MySQL Connector/J" jdbc driver available here
I have used java.sql.CallableStatement in the java class.
The Table in mysql is: -
-----------------------------------------------------------------------
DROP TABLE IF EXISTS `test_post`;
CREATE TABLE `test_post` (
`Post_Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Subject` varchar(50) NOT NULL,
`Post_msg` text NOT NULL,
PRIMARY KEY (`Post_Id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-----------------------------------------------------------------------
The stored procedure is: -
-----------------------------------------------------------------------
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_select_test_post`(in id integer)
BEGIN
SELECT * FROM test_post where post_id=id;
END
-----------------------------------------------------------------------
The java code: -
-----------------------------------------------------------------------
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//System.out.print();
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/void?" + "user=myUsername&password=myPassword");
CallableStatement stmt = conn.prepareCall(" call sp_select_test_post(?) ");
stmt.setInt(1, 2);
stmt.execute();
ResultSet rs = stmt.getResultSet();
/*ResultSetMetaData rmeta = rs.getMetaData();
System.out.print(rmeta.getColumnCount());*/
while(rs.next()) {
System.out.print(rs.getString(2) + "\n");
}
System.out.print("connected");
conn.close();
}
catch (ClassNotFoundException cnfe) {
System.out.print(cnfe);
}
catch(InstantiationException ie) {
System.out.print(ie);
}
catch(IllegalAccessException iae) {
System.out.print(iae);
}
catch(SQLException sqle) {
System.out.print(sqle);
}
}
}
-----------------------------------------------------------------------
Hope that runs in your systems too... Good Luck..
Please post any better implementation ... thanks...
Cheers!!!
Pradyut Kumar Bhattacharya
http://pradyut.tk
http://oop-edge.spaces.msn.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
New Delhi, India
any better implementation is always a welcome....
I have used "MySQL Connector/J" jdbc driver available here
I have used java.sql.CallableStatement in the java class.
The Table in mysql is: -
-----------------------------------------------------------------------
DROP TABLE IF EXISTS `test_post`;
CREATE TABLE `test_post` (
`Post_Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Subject` varchar(50) NOT NULL,
`Post_msg` text NOT NULL,
PRIMARY KEY (`Post_Id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-----------------------------------------------------------------------
The stored procedure is: -
-----------------------------------------------------------------------
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_select_test_post`(in id integer)
BEGIN
SELECT * FROM test_post where post_id=id;
END
-----------------------------------------------------------------------
The java code: -
-----------------------------------------------------------------------
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//System.out.print();
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/void?" + "user=myUsername&password=myPassword");
CallableStatement stmt = conn.prepareCall(" call sp_select_test_post(?) ");
stmt.setInt(1, 2);
stmt.execute();
ResultSet rs = stmt.getResultSet();
/*ResultSetMetaData rmeta = rs.getMetaData();
System.out.print(rmeta.getColumnCount());*/
while(rs.next()) {
System.out.print(rs.getString(2) + "\n");
}
System.out.print("connected");
conn.close();
}
catch (ClassNotFoundException cnfe) {
System.out.print(cnfe);
}
catch(InstantiationException ie) {
System.out.print(ie);
}
catch(IllegalAccessException iae) {
System.out.print(iae);
}
catch(SQLException sqle) {
System.out.print(sqle);
}
}
}
-----------------------------------------------------------------------
Hope that runs in your systems too... Good Luck..
Please post any better implementation ... thanks...
Cheers!!!
Pradyut Kumar Bhattacharya
http://pradyut.tk
http://oop-edge.spaces.msn.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
New Delhi, India
Saturday, June 28, 2008
Re: java code to evaluate a arithmetic expression....
The code better implemented: -
Please review and suggest a better implementation.
Any comments are welcome.
Download the code at: -
http://myjavaserver.com/~pradyut/files/Calci.java
The code: -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Calci {
public static void main(String[] args) {
String a = "4-(6-1)+3*9/2(8(6-1))(7-43)4-(6-1)+3.67*9/2(8(6.77+1))(7-4.3)"; //1*3+2*7-1-1
//(2+1)-(4-2)3/(-5)
//3*(1-2)
//4-(6-1)+3*9/2(8(6-1))(7-43)
//14-(4/(6-9))
String[] b = null;
String c = null;
Calci obj = new Calci();
System.out.println(obj.parse(a));
}
double func(String a) {
double d = 0;
return d;
}
String mult(String a, String b) {
double c = func1(a) * func1(b);
return (Double.toString(c));
}
String minus(String a, String b) {
double c = func1(a) - func1(b);
System.out.println(c);
return (Double.toString(c));
}
String add(String a, String b) {
double c = func1(a) + func1(b);
return (Double.toString(c));
}
String divide(String a, String b) {
double c = func1(a) / func1(b);
return (Double.toString(c));
}
double func1(String a) {
double d =0;
try {
d = Double.parseDouble(a);
} catch (NumberFormatException n1) {
System.out.println(n1);
}
return d;
}
String parse(String a) {
String b = null;
String c = null, d= null, e=null;
int z=0, f=0;
if(a.contains("(")) {
//System.out.println(b[0]);
z = a.lastIndexOf("(");
f = a.indexOf(")", z)+1;
c = a.substring(z, f);
b =a.substring(0, z);
d = a.substring(f, a.length());
//processing b
if(b.length() >=1) {
e = String.valueOf(b.charAt(b.length()-1));
if(e.equals("+") || e.equals("-") || e.equals("*") || e.equals("/") || e.equals("(")) {
}else
{
b = b+ "*";
}
//System.out.println("b is: " + b);
}
//processing d
if(d.length() >1) {
e = String.valueOf(d.charAt(0));
if(e.equals("+") || e.equals("-") || e.equals("*") || e.equals("/") || e.equals(")")) {
}else
{
d = "*" + d;
}
//System.out.println("d is: "+d);
}
c = check(brackets(c));
//System.out.println("c is: "+c);
//c = "5";
a = b + c + d;
if(a.contains("*-")) {
//System.out.println("inside a is: "+a);
z = a.indexOf("*-");
b = a.substring(0, z);
//System.out.println("inside b is: "+b);
a = a.substring(z, a.length());
b = repl(b);
//System.out.println("inside a is: "+a);
a= a.replace("*-", "*");
a = b+a;
} else if (a.contains("--")) {
a= a.replace("--", "+");
} else if (a.contains("+-")) {
a= a.replace("+-", "-");
} else if (a.contains("/-")) {
z = a.indexOf("/-");
b = a.substring(0, z);
//System.out.println("inside b is: "+b);
a = a.substring(z, a.length());
/*if( b.lastIndexOf('+') > b.lastIndexOf('-'))
b=b.replace(b.charAt(b.lastIndexOf('+')), '-');
else
b=b.replace(b.charAt(b.lastIndexOf('-')), '+');
*/
b=repl(b);
//System.out.println("inside a is: "+a);
a= a.replace("/-", "/");
a = b+a;
}
System.out.println("a is: "+a);
return parse(a);
//System.out.println(a.substring(a.lastIndexOf("(")+1, a.indexOf(")", z)));
}
else
return check(a);
}
String repl(String b) {
int j,k,l;
String h;
if(b.length() >1)
{
if(b.contains("+") || b.contains("-")) {
j = b.lastIndexOf('+');
k = b.lastIndexOf('-');
l = b.lastIndexOf(')');
if (l<j || l<k) {
if( b.lastIndexOf('+') > b.lastIndexOf('-'))
{
System.out.println("inside");
b=b.replace(b.charAt(b.lastIndexOf('+')), '-');
return b;
}
else
{
//System.out.println("test B");
System.out.println("inside 1");
b=b.replace(b.charAt(b.lastIndexOf('-')), '+');
return b;
}
} else {
System.out.println("inside 2");
h = b.substring(0, b.lastIndexOf('('));
System.out.println("h is: "+h);
b = b.substring(b.lastIndexOf('('), b.length());
System.out.println("b is: "+b);
if( h.lastIndexOf('+') > h.lastIndexOf('-'))
{
//System.out.println("test A");
h=h.replace(h.charAt(h.lastIndexOf('+')), '-');
b = h+b;
return b;
}
else
{
//System.out.println("test B");
h=h.replace(h.charAt(h.lastIndexOf('-')), '+');
b = h+ b;
return b;
}
}
}
else
{
b = "-" + b;
return b;
}
} else
{
b = "-" + b;
return b;
}
}
String brackets(String b) {
b = b.replace("(", "");
b = b.replace(")", "");
return b;
}
String check(String a) {
String[] b=null;
if(a.indexOf('+')==0) {
a=a.substring(1);
check(a);
}
if(a.contains("+")) {
//System.out.println("This is inside minus");
/*if(a.indexOf('+') ==0) {
a=a.substring(1);
}*/
b = a.split("\\+",2);
a=add(check1(b[0]),check(b[1])) ;
return a;
}
else
return check1(a);
}
private String check1(String a) {
String[] b=null;
if(a.contains("-")) {
if(a.indexOf('-')==0)
{
a =a.substring(1);
if(a.contains("-")) {
b = a.split("-", 2);
b[0] = "-" + b[0];
b[1] = "-" + b[1];
a = add(check2(b[0]), check1(b[1]));
}
else {
//System.out.println("this is here");
a = "-"+a;
a = check2(a);
}
} else {
b = a.split("-", 2);
//b[0] = "-" + b[0];
b[1] = "-" + b[1];
a = add(check2(b[0]), check1(b[1]));
}
return a;
}else
return check2(a);
//throw new UnsupportedOperationException("Not yet implemented");
}
private String check2(String a) {
String[] b=null;
if(a.contains("*")) {
b = a.split("\\*",2);
a = mult(check3(b[0]), check2(b[1])) ;
return a;
}
else
return check3(a);
//throw new UnsupportedOperationException("Not yet implemented");
}
private String check3(String a) {
String[] b=null;
if(a.contains("/")) {
b = a.split("\\/");
a = divide(b[0], check3(b[1])) ;
return a;
}
else
return a;
//throw new UnsupportedOperationException("Not yet implemented");
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks
--
Pradyut
http://pradyut.tk
http://www.pradyut.co.nr/
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://groups.google.com/group/oop_programming
India
Please review and suggest a better implementation.
Any comments are welcome.
Download the code at: -
http://myjavaserver.com/~pradyut/files/Calci.java
The code: -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Calci {
public static void main(String[] args) {
String a = "4-(6-1)+3*9/2(8(6-1))(7-43)4-(6-1)+3.67*9/2(8(6.77+1))(7-4.3)"; //1*3+2*7-1-1
//(2+1)-(4-2)3/(-5)
//3*(1-2)
//4-(6-1)+3*9/2(8(6-1))(7-43)
//14-(4/(6-9))
String[] b = null;
String c = null;
Calci obj = new Calci();
System.out.println(obj.parse(a));
}
double func(String a) {
double d = 0;
return d;
}
String mult(String a, String b) {
double c = func1(a) * func1(b);
return (Double.toString(c));
}
String minus(String a, String b) {
double c = func1(a) - func1(b);
System.out.println(c);
return (Double.toString(c));
}
String add(String a, String b) {
double c = func1(a) + func1(b);
return (Double.toString(c));
}
String divide(String a, String b) {
double c = func1(a) / func1(b);
return (Double.toString(c));
}
double func1(String a) {
double d =0;
try {
d = Double.parseDouble(a);
} catch (NumberFormatException n1) {
System.out.println(n1);
}
return d;
}
String parse(String a) {
String b = null;
String c = null, d= null, e=null;
int z=0, f=0;
if(a.contains("(")) {
//System.out.println(b[0]);
z = a.lastIndexOf("(");
f = a.indexOf(")", z)+1;
c = a.substring(z, f);
b =a.substring(0, z);
d = a.substring(f, a.length());
//processing b
if(b.length() >=1) {
e = String.valueOf(b.charAt(b.length()-1));
if(e.equals("+") || e.equals("-") || e.equals("*") || e.equals("/") || e.equals("(")) {
}else
{
b = b+ "*";
}
//System.out.println("b is: " + b);
}
//processing d
if(d.length() >1) {
e = String.valueOf(d.charAt(0));
if(e.equals("+") || e.equals("-") || e.equals("*") || e.equals("/") || e.equals(")")) {
}else
{
d = "*" + d;
}
//System.out.println("d is: "+d);
}
c = check(brackets(c));
//System.out.println("c is: "+c);
//c = "5";
a = b + c + d;
if(a.contains("*-")) {
//System.out.println("inside a is: "+a);
z = a.indexOf("*-");
b = a.substring(0, z);
//System.out.println("inside b is: "+b);
a = a.substring(z, a.length());
b = repl(b);
//System.out.println("inside a is: "+a);
a= a.replace("*-", "*");
a = b+a;
} else if (a.contains("--")) {
a= a.replace("--", "+");
} else if (a.contains("+-")) {
a= a.replace("+-", "-");
} else if (a.contains("/-")) {
z = a.indexOf("/-");
b = a.substring(0, z);
//System.out.println("inside b is: "+b);
a = a.substring(z, a.length());
/*if( b.lastIndexOf('+') > b.lastIndexOf('-'))
b=b.replace(b.charAt(b.lastIndexOf('+')), '-');
else
b=b.replace(b.charAt(b.lastIndexOf('-')), '+');
*/
b=repl(b);
//System.out.println("inside a is: "+a);
a= a.replace("/-", "/");
a = b+a;
}
System.out.println("a is: "+a);
return parse(a);
//System.out.println(a.substring(a.lastIndexOf("(")+1, a.indexOf(")", z)));
}
else
return check(a);
}
String repl(String b) {
int j,k,l;
String h;
if(b.length() >1)
{
if(b.contains("+") || b.contains("-")) {
j = b.lastIndexOf('+');
k = b.lastIndexOf('-');
l = b.lastIndexOf(')');
if (l<j || l<k) {
if( b.lastIndexOf('+') > b.lastIndexOf('-'))
{
System.out.println("inside");
b=b.replace(b.charAt(b.lastIndexOf('+')), '-');
return b;
}
else
{
//System.out.println("test B");
System.out.println("inside 1");
b=b.replace(b.charAt(b.lastIndexOf('-')), '+');
return b;
}
} else {
System.out.println("inside 2");
h = b.substring(0, b.lastIndexOf('('));
System.out.println("h is: "+h);
b = b.substring(b.lastIndexOf('('), b.length());
System.out.println("b is: "+b);
if( h.lastIndexOf('+') > h.lastIndexOf('-'))
{
//System.out.println("test A");
h=h.replace(h.charAt(h.lastIndexOf('+')), '-');
b = h+b;
return b;
}
else
{
//System.out.println("test B");
h=h.replace(h.charAt(h.lastIndexOf('-')), '+');
b = h+ b;
return b;
}
}
}
else
{
b = "-" + b;
return b;
}
} else
{
b = "-" + b;
return b;
}
}
String brackets(String b) {
b = b.replace("(", "");
b = b.replace(")", "");
return b;
}
String check(String a) {
String[] b=null;
if(a.indexOf('+')==0) {
a=a.substring(1);
check(a);
}
if(a.contains("+")) {
//System.out.println("This is inside minus");
/*if(a.indexOf('+') ==0) {
a=a.substring(1);
}*/
b = a.split("\\+",2);
a=add(check1(b[0]),check(b[1])) ;
return a;
}
else
return check1(a);
}
private String check1(String a) {
String[] b=null;
if(a.contains("-")) {
if(a.indexOf('-')==0)
{
a =a.substring(1);
if(a.contains("-")) {
b = a.split("-", 2);
b[0] = "-" + b[0];
b[1] = "-" + b[1];
a = add(check2(b[0]), check1(b[1]));
}
else {
//System.out.println("this is here");
a = "-"+a;
a = check2(a);
}
} else {
b = a.split("-", 2);
//b[0] = "-" + b[0];
b[1] = "-" + b[1];
a = add(check2(b[0]), check1(b[1]));
}
return a;
}else
return check2(a);
//throw new UnsupportedOperationException("Not yet implemented");
}
private String check2(String a) {
String[] b=null;
if(a.contains("*")) {
b = a.split("\\*",2);
a = mult(check3(b[0]), check2(b[1])) ;
return a;
}
else
return check3(a);
//throw new UnsupportedOperationException("Not yet implemented");
}
private String check3(String a) {
String[] b=null;
if(a.contains("/")) {
b = a.split("\\/");
a = divide(b[0], check3(b[1])) ;
return a;
}
else
return a;
//throw new UnsupportedOperationException("Not yet implemented");
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks
On Sun, Dec 30, 2007 at 11:10 PM, Pradyut Bhattacharya <pradyutb@gmail.com> wrote:
Java code to evaluate in arithmetic expression......
following order...
Division
Multiplication
Subtraction
Addition
The code: -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<snip>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Reply any comments or suggestions.......
Thanks....
--
Pradyut
http://pradyut.tk
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://www.flickr.com/photos/praddy
http://groups.google.com/group/oop_programming
India
--
Pradyut
http://pradyut.tk
http://www.pradyut.co.nr/
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://groups.google.com/group/oop_programming
India
Thursday, June 05, 2008
IT Companies Full Names...just don't miss it. :-)
1. NIIT: Not Interested in IT
2. WIPRO: Weak Input, Poor & Rubbish Output
3. HCL: Hidden Costs & Losses
4. TCS : Totally Confusing Solutions
5. INFOSYS : Inferior Offline Systems
6. HUGHES : Highly Useless Graduates Hired for Eating and Sleeping
7. BAAN : Beggars Association and Nerds
8. IBM : Implicitly Boring Machines
9. SATYAM: Sad and Tired Yelling Away Madly
10. PARAM: Puzzled and Ridiculous Array of Microprocessors
11. C-DOT : Coffee during Office Timings
12. AT&T : All Troubles & Terrible
13. CMC : Coffee, Meals and Comfort
14. DEC : Drifting & Exhausted Computers
15. BFL : Brainwash first and Let them go
17. TISL : Totally Inconsistent Systems Ltd.
18. PSI : Peculiar Symptoms of India
19. ORACLE: On-line Romance And Chatting with Lady Employees .
20. PATNI : Pathetic Appraisal Techniques
--
Pradyut
http://pradyut.tk
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://www.flickr.com/photos/praddy
http://groups.google.com/group/oop_programming
India
2. WIPRO: Weak Input, Poor & Rubbish Output
3. HCL: Hidden Costs & Losses
4. TCS : Totally Confusing Solutions
5. INFOSYS : Inferior Offline Systems
6. HUGHES : Highly Useless Graduates Hired for Eating and Sleeping
7. BAAN : Beggars Association and Nerds
8. IBM : Implicitly Boring Machines
9. SATYAM: Sad and Tired Yelling Away Madly
10. PARAM: Puzzled and Ridiculous Array of Microprocessors
11. C-DOT : Coffee during Office Timings
12. AT&T : All Troubles & Terrible
13. CMC : Coffee, Meals and Comfort
14. DEC : Drifting & Exhausted Computers
15. BFL : Brainwash first and Let them go
17. TISL : Totally Inconsistent Systems Ltd.
18. PSI : Peculiar Symptoms of India
19. ORACLE: On-line Romance And Chatting with Lady Employees .
20. PATNI : Pathetic Appraisal Techniques
--
Pradyut
http://pradyut.tk
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://www.flickr.com/photos/praddy
http://groups.google.com/group/oop_programming
India
Monday, April 07, 2008
Re: simple css menu
Thursday, March 20, 2008
forms authentication and session variables
Forms authentication and session variables in asp.net
navigate between default and webform3 for sessions
navigate to webform2 for forms authentication
Sources at: -
http://myjavaserver.com/%7Epradyut/files/WebApplication2.zip
--
Pradyut
http://pradyut.tk
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://www.flickr.com/photos/praddy
http://groups.google.com/group/oop_programming
India
navigate between default and webform3 for sessions
navigate to webform2 for forms authentication
Sources at: -
http://myjavaserver.com/%7Epradyut/files/WebApplication2.zip
--
Pradyut
http://pradyut.tk
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://www.flickr.com/photos/praddy
http://groups.google.com/group/oop_programming
India
Sunday, March 16, 2008
changing to absolute positioning in visual web 2008
changing to absolute positioning visual web in visual studio 2008
Thanks
--
Pradyut
http://pradyut.tk
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://www.flickr.com/photos/praddy
http://groups.google.com/group/oop_programming
India
- In VWD 2008 express goto Tools --> Options --> click show all settings --> expand HTML Designer --> select CSS Styling
- check the option to "change positioning to absolute for controls added using Toolbox, paste or drag and drop
Thanks
--
Pradyut
http://pradyut.tk
http://oop-edge.blogspot.com/
http://pradyutb.blogspot.com/
http://praddy-photos.blogspot.com/
http://oop-edge.spaces.live.com/
http://www.flickr.com/photos/praddy
http://groups.google.com/group/oop_programming
India
Subscribe to:
Posts (Atom)