This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception in thread "main" java.sql.SQLException" Watch "Exception in thread "main" java.sql.SQLException" New topic

Exception in thread "main" java.sql.SQLException

vicky verma

Joined: Jan 04, 2007
Posts: 5
import java.sql.DriverManager;
import java.sql.*;
public class DataConnect {
public static void main(String[] args) throws SQLException,ClassNotFoundException,UnsupportedClassVersionError{

Connection con=null;
Statement st=null;
ResultSet rs=null;
con=DriverManager.getConnection("jdbc racle:thin:@sun:1521:roshan","vikas","verma");

rs=st.executeQuery("select emp_id,f_name,l_name from emp");




Will this program run or not.if not then what is the reason please explain me.

emp_id is of type number.
f_name,l_name is of type varchar.

before answering ,please read this paragraph carefully

For example, the method getInt can be used to retrieve any of the numeric or character types. The data it retrieves will be converted to an int; that is, if the SQL type is VARCHAR , JDBC will attempt to parse an integer out of the VARCHAR. The method getInt is recommended for retrieving only SQL INTEGER types, however, and it cannot be used for the SQL types BINARY, VARBINARY, LONGVARBINARY, DATE , TIME, or TIMESTAMP.
Jan Cumps

Joined: Dec 20, 2006
Posts: 2491


Please show us the error message.
Upon first review, I think first_name and Last_name are Strings:Regards, Jan

OCUP UML fundamental and ITIL foundation
youtube channel
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Post the exception stacktrace.

As your exception is going out of main method , the main thread would be killed once exception is thrown.

Rahul Bhattacharjee
LinkedIn - Blog
Consider Paul's rocket mass heater.
subject: Exception in thread "main" java.sql.SQLException
Similar Threads
mySQL INTEGER == LONG in Java and ....???
javax.jms.JMSSecurityException: User null is NOT authenticated
stuck up in the problem
Using reflection to get the value of a final static field
How to know the Data-type of column?