• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can getString method retrive integer type variables ? And what is the problem with this code?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a table emp10 using SQL Developer

create table emp10(
empid integer primary key,
ename varchar2(30)
);
select * from emp10;

I have attached the data in the table in form of a picture attachment





I am getting this error

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Unknown Source)
       at Test.main(Test.java:6)


But my question is not only this


I have another question -  here we are retrieving the empid , which is a integer datatype variable using getString method , does this works  or we have use  getInt method ?
table.png
[Thumbnail for table.png]
run.png
[Thumbnail for run.png]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Do you have the Oracle JDBC driver installed? And specified in your classpath?

Henry
 
samar das
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Henry Wong   i have attached a screenshot

I have copied all 3 jar files from jdbc subfolder of oraclexe  to  java > JDK >  LIB

Will that be OK ?

file.png
[Thumbnail for file.png]
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

samar das wrote:
I have copied all 3 jar files from jdbc subfolder of oraclexe  to  java > JDK >  LIB

Will that be OK ?



What is wrong with using the classpath?  It is the officially supported method, and it works well.

As for using the JRE/JDK library directory, I am sure there is a way to do that... but I believe that it is highly not recommended, and hence, I don't use it at all.

Henry
 
samar das
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Henry Wong   can you answer my other question

I have another question - here we are retrieving the empid , which is a integer datatype variable using getString method , does this works or we have use getInt method ?

 
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

samar das wrote:I have another question - here we are retrieving the empid , which is a integer datatype variable using getString method , does this works or we have use getInt method ?

Yes you can retrieve int data type using getString method of ResultSet which retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language. Will be good to read getString() method and getInt() method
Since

JLS 8 5.1.11. String Conversion wrote:Any type may be converted to type String by string conversion. A value x of primitive type T is first converted to a reference value as if by giving it as an argument to an appropriate class instance creation expression. If T is byte, short, or int, then use new Integer(x). This reference value is then converted to type String by string conversion.

With getInt() you can always retrieve int value but if the column data type is varchar and you try to retrieve using getInt() method then it gives SQLException: Invalid value for getInt().

 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might be able to get a String with the same text as the number by using getString on an int column, but you probably don't want to. Remember that a String is not a number and a number is not a String.

If you go through the ResultSet documentation, it refers you to the JDBC Specification which tells you whether you can get a particular datatype from a particular method in a ResultSet.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic