Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

Shantanu Deshmukh

Greenhorn
+ Follow
since Jul 28, 2011
Shantanu likes ...
Java jQuery PHP
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 Shantanu Deshmukh

@jan cumps,

I did that typo deliberately. to get that exception. only to find out that it is throwing nested exception. i want to find out a way to get inner exception class name
So this is the function I am going to use.

How can I use SQLException here?
7 years ago
Hi,

I am trying to connect to mysql database. I am using try catch while establishing connection.
I want that I should be able to know what exception was caught, so that, I can show appropriate error message.
e.g if I pass incorrect hostname, i should show Wrong hostname provided.
One way to do is get class name of runtime exception class. but nested exception is being thrown like this..

There was some error while establishing connection to the databasecom.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.UnknownHostException
MESSAGE: localhsost

STACKTRACE:

java.net.UnknownHostException: localhsost
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:867)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1246)
at java.net.InetAddress.getAllByName0(InetAddress.java:1197)
at java.net.InetAddress.getAllByName(InetAddress.java:1128)
at java.net.InetAddress.getAllByName(InetAddress.java:1064)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:246)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:222)
at accessMySQL.accessMySQL.createConnection(accessMySQL.java:24)
at test.main(test.java:16)


** END NESTED EXCEPTION **



Last packet sent to the server was 1 ms ago.
Problem in establishing connection.


Now I would like to know that class name UnknownHostException, so I can setup a condition like


please help !!
Hello,

I am trying to connect to mysql database using JDBC. I have applied exception handling. However simply printing exception object is amateur. I want to know exact reason of exception.
For example, if I give wrong hostname it should give me exception that Hostname was incorrect.
How to go about it ?

7 years ago
Hello,
I am trying to write a function which takes stored procedure's name and it's arguments as argument and execute it.
Now I want that, the function should be able to know wat data is being output from the sp, so I can set datatype of output variable of sp.

How to do this ?
Hello, I have this function which calls a stored procedure


executing this function gives me this error:

There was some error while making Prepared Call.
Error Descrption: java.sql.SQLException: Callable statments not supported.


Please help !!
Hey folks, got a solution for that.
zeroDateTimeBehavior=convertToNull add this as a parameter in JDBC connection url to slove this problem

Hope this helps to whoever reaching to this problem
Hello,
I am writing a simple jdbc program, which will print data column in my table. I use this statement users.getString('update_time')
The field in my database contains, for e.g, this value 2010-01-12 20:54:35.0.
The program prints this value, but also throws exception as Cannot convert value '0000-00-00 00:00:00' from column 7 to TIMESTAMP.

Please help !!
hi all, thanks for your input.
The connection URL was wrong in the program. I also had not included com folder provided with the connector. This all is working in Eclipse now.
Still not much clue how to run it all on command prompt.
I am also trying on eclipse. There I get No suitable driver found for the same program. i have imported external JAR, that mysql connector one. no luck there either.
by the way is this url format wrong ?

this is the command
java -cp /home/shantanu/DEV_DOCS/SOAP/mysql-connector-java-5.0.8-bin.jar:. acessMySQL

this is the error:

Exception in thread "main" java.lang.NoClassDefFoundError: acessMySQL
Caused by: java.lang.ClassNotFoundException: acessMySQL
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Could not find the main class: acessMySQL. Program will exit.
Hey vijay, thanks for that hint.
But now I am getting class not found exception !! the path I just gave is the same path where my class file lies. What else could I be missing.
I understand now, that the basics like classpath, java_home are not that clear to me. please help me if I am wrong with them, in this case.
(I really want to learn java, lest I clear these obstacles )
I m doing everything you folks are telling me. I entered this command while compiling
javac accessMySQL.java

compiled with no errors.

While running:
java -cp /home/shantanu/DEV_DOCS/SOAP/mysql-connector-java-5.0.8-bin.jar;. acessMySQL

I am showing full list of java options !!! why isn't this working ???
i wrote the exact command you gave me, but then all options related to java command were shown, meaning it was not a correct command or did not have correct options.

sorry for bugging, but more help needed. I am on this since the whole day, but cant get it to work !!
I hit this command

java -cp /home/shantanu/mysql-connector-java-5.0.8-bin.jar accessMySQL

and now it give me class not found exception java.lang.ClassNotFoundException: accessMySQL

help !!