Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!

omar salem

Ranch Hand
+ Follow
since Aug 22, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by omar salem

Thank you Paul. The thing is that I had no Idea of such features in java otherwise I wouldn't have posted my Query. However, the hints you dropped are valuable. Thanks again
9 years ago
Thank you but how %s differs from $1?...I mean is that a format that could be easily replaced? and I don't have to use the conventions I mentioned. I just put them as examples and I wanted to know how could any part of a given string be replaced during whatever execution?
9 years ago
Hey ranchers,
I am new to java and I have this query:
Lets say I have the following string : String s = " Dear $1
This is to inform you that $2 is being postponed to $3"

Now simply $1, $2, $3 have to be replaced by some database fields during sending of this message to recipients.
the question is how would my string object s process this string and replace $1,$2,$3 with the appropriate fields from the database? Any clue how to do this?
9 years ago
Dear Ranchers,

I am developing a simple JDBC application simulating the four basic operations performed on a database. The insert,delete, and retrieve operations are working fine but for the update operation the executeUpdate() method is executed but no effects reflect on the database.The database on which the application is developed is MS-Access. Here is the code i am using :



I would appreciate your help thanking you in advance.
Thanks alot for the fast reply.
13 years ago
Hi Ranchers,
Whats the event that i can use if i want to show button name when that button get focus ( Only Selected but NOT Entered ) or when i move the mousre over it?

Thanks in advance.
Omar Salem
13 years ago
Thanks for your help.......I really got it to work now...Thanks again
Omar Salem
Thanks Bear....Never known about code tags before
Hi Ranchers,

I am trying to validate a user name and a password by comparing details in the database with those provided by the user inside the text fields of the simple frame created for this test. the condition gets always true even if the entries do not match details from the database and always gives me the message "Match Found". Here is the code i worte for this :


I would appreciate your help and fast response.
Omar Salem
Hi Ranchers,

I have built a small GUI application using Swing that has one text field and three buttons named first,next,and last respictevely. Using these buttons i want to traverse through the ResultSet object.
when i click on the 'first button' it works fine and retrives the first record from the database.
This is the logic i applied for the 'first' button :
if(ae.getSource()==first)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:omah");
query = " select * from data1";
st = con.createStatement();
rs = st.executeQuery(query);
while(rs.next())
{
if(rs.getRow()==1)
//System.out.println(rs.getString(1));
t.setText(rs.getString(1));
else
{
while(rs.last())
{
t.setText(rs.getString(1));
}
}

}
}
catch(Exception e)
{
System.out.println(e);
}

now for the 'next' button which will fetch the next record in the database i have read the current cursor position using getRow() method then i increased it by 1 so that the cursor moves to the next record and fetch it then display its value in the text field. Here is the code i applied for this :
if(ae.getSource()==next)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:omah");
query = " select * from data1";
System.out.println("Hi");
System.out.println("Hi");
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = st.executeQuery(query);
System.out.println("Hi");
int i = rs.getRow();
i = i+1;
System.out.println("Hi");
boolean b = rs.absolute(i);
t.setText(rs.getString(1));

}

catch(Exception e)
{
System.out.println(e);
}
}
i was trying to use the absolute() method but couldnt actually get to the next record. All i need is some help in traversing for first, next, end ad so on.

Regards
Omar Salem
Thank you all. That really helped....I really appreciate it.
Omar Salem
13 years ago
Thanks for you both......I already know that there is a Math.sqrt() method but that would calculate the square root for me. what i am trying to do is to make my program calculate the square root without using any built in methods.

Thanks again
Omar Salem
13 years ago
Hi Ranchers

I am trying to make a java program that calculates the square root of a given number. I used a mathematical formula to generate the square root called Bakhshali approximation. It states that if (N square) is the nearest perfect square to the number S. S is the number we are finding the square root for then the square root of S is calculated as follows:
1- D = S-(N square)
2- P = D/2N
3- A = N + P
4- then square root of S is approximately given by A - (p square)/2A

now in my program i have written the above calculations but the problem i am facing now is how to make my program selects the nearest perfect square.

i have tried to take a while loop to find the squares of the numbers less than or equal to the value of S. then comparing these squares one by one with S until i get the nearest square.



i know it my code has a lot of errors but would any one suggest something.
I would appreciate your help.

Omar Salem
[edit]Add code tags. CR[/edit]
[ December 04, 2008: Message edited by: Campbell Ritchie ]
13 years ago
Hi everyone
I am new to jdbc programming. I am trying to design a jdbc application through wich user will be able to pass table name and table structure during run time. My program would ask the user to pass table name and table fields through the console then it would create the specified table at the target database. I have tried the PreparedStatement interface but could not actually get to the method that would serve the purpose.

I have tried this code :

public void tableCreation()
{
BufferedReader br = new BufferedReader(new(InputStreamReader(System.in)));
System.out.println("Enter Table's Name:");
String tablename = br.readLine();
System.out.println("Enter filed name :");
String field1 = br.readLine();
System.out.println("Enter Filed Size");
int i = Integer.parseInt(br.readLine());

// and so on for the remaining fields.
//Can i use PreparedStatement object for that?
// How would my query to the database look like?

PreparedStatement pst = con.createStatement();
pst.execute(query);
}

Would highly appreciate your help.

Omar Salem
We are two different people...but brothers
14 years ago