473,786 Members | 2,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error in Assigning a value got from the SQL DB

5 New Member
Hi,
In this program, i have established the connection and it even works. i get a value from the table and checked it with the given value . if both r same, i have to assign that value to a string. But if i try assigning the value to a string variable, it goes out of the try statement to the catch statement..can u please help me what's wrong and why its not working....than k you.

i have given the print statement inside the if condition..its working. but the variable assignment is not working.

Expand|Select|Wrap|Line Numbers
  1. try
  2.             {     
  3.                   login_name=usert.getText().trim();
  4.                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
  5.                   String url = "jdbc:odbc:sakthi"; 
  6.                   con = (Connection)DriverManager.getConnection(url,"sakthi","");
  7.                   Statement stmt=con.createStatement();
  8.                   System.out.println("Connection :"+con);
  9.                   System.out.println("Connection is created!"+login_name);
  10.                   String run=("select * from logg");
  11.                   ResultSet rs=stmt.executeQuery(run);
  12.                   while(rs.next())                        
  13.                 {   
  14.  
  15.                      if(rs.getString("user").trim().equalsIgnoreCase(login_name.trim()))
  16.                      {
  17.                      System.out.println("hello");     
  18.                      //uid=rs.getString("user");
  19.                      // System.out.println(uid);
  20.  
  21.                      }
  22.                      else
  23.                      {
  24.                          System.out.println(" bye");
  25.                      }
  26.  
  27.                   }con.close();
  28.             }
  29.                 catch(Exception s)
  30.                 {
  31.                   System.out.println("Doesn't establish the connection!");
  32.                   System.exit(0);
  33.                 }
  34.  
  35.         }
Sep 29 '07 #1
1 1439
r035198x
13,262 MVP
Hi,
In this program, i have established the connection and it even works. i get a value from the table and checked it with the given value . if both r same, i have to assign that value to a string. But if i try assigning the value to a string variable, it goes out of the try statement to the catch statement..can u please help me what's wrong and why its not working....than k you.

i have given the print statement inside the if condition..its working. but the variable assignment is not working.

Expand|Select|Wrap|Line Numbers
  1. try
  2.             {     
  3.                   login_name=usert.getText().trim();
  4.                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
  5.                   String url = "jdbc:odbc:sakthi"; 
  6.                   con = (Connection)DriverManager.getConnection(url,"sakthi","");
  7.                   Statement stmt=con.createStatement();
  8.                   System.out.println("Connection :"+con);
  9.                   System.out.println("Connection is created!"+login_name);
  10.                   String run=("select * from logg");
  11.                   ResultSet rs=stmt.executeQuery(run);
  12.                   while(rs.next())                        
  13.                 {   
  14.  
  15.                      if(rs.getString("user").trim().equalsIgnoreCase(login_name.trim()))
  16.                      {
  17.                      System.out.println("hello");     
  18.                      //uid=rs.getString("user");
  19.                      // System.out.println(uid);
  20.  
  21.                      }
  22.                      else
  23.                      {
  24.                          System.out.println(" bye");
  25.                      }
  26.  
  27.                   }con.close();
  28.             }
  29.                 catch(Exception s)
  30.                 {
  31.                   System.out.println("Doesn't establish the connection!");
  32.                   System.exit(0);
  33.                 }
  34.  
  35.         }
Expand|Select|Wrap|Line Numbers
  1. if(rs.getString("user").trim().equalsIgnoreCase(login_name.trim()))
Retrieves data from column user. Then inside the if block you are trying to call rs.getString("u ser") again. That according to the specs may not yield the correct results. Only call getString once for that given column. If you have done s.printStackTra ce(); (you should) in your catch block you will have seen the exception that was thrown because of that.
And I spent the whole day yesterday pointing that out.
Sep 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

17
7464
by: Steve Jorgensen | last post by:
If you've ever employed custom error numbers and messages in you programs, you've probably ended up with code similar to what I've ended up with in the past something like... <code> public Const xyzcErrNumBase As Long = 500 Public Const xyzcErrNumHeyDontDoThat = xyzcErrNumBase + 1 Public Const xyzcErrTxtHeyDontDoThat = "Hey! Don't do that!"
7
1670
by: Leon Shaw | last post by:
Need help understanding? Server Error in '/solo' Application. ---------------------------------------------------------------------------- ---- Object must implement IConvertible. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
7
8241
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
5
2014
by: johnny | last post by:
I have the following PHP code. I am using PHP 5.1.6. $req =& new HTTP_Request($this->accessUrl); I am getting the following errors: Strict Standards: Assigning the return value of new by reference is deprecated in c:\mysite\lib\simpleTest.php on line 80 Can anyone tell why is this? Does it mean assigning the return value of new by reference is not supported in PHP 5.1.6?
8
1134
by: Steven Spencer \(Spinalogic\) | last post by:
Dim dlg As New dlgChangeDate Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please Enter the Start of the Holiday") If (Not fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) Then While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue) MsgBox("The date you have entered does not occur between the
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.