i cant find any compile time error but there is runtime error.

i cant find any compile time error but there is runtime error.

import java.sql.*;

public class JDBCExample{ public static void main(String args[]) {

    try{
 Connection con;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:datastud"); try{ System.out.println("Getting All Rows from a table!"); Statement st = con.createStatement(); ResultSet res = st.executeQuery("SELECT * FROM college"); System.out.println("studentcode: " + "\t" + "studentname: "); while (res.next()) { int i = res.getInt("stud_code"); String s = res.getString("stud_name"); System.out.println(i + "\t\t" + s); } con.close(); } catch (SQLException s){ System.out.println("SQL code does not execute."); }} catch (Exception e){ System.out.println("Error:connection not created"); }

View Answers

October 30, 2010 at 11:00 PM

Hi,

I tried the following updated code and it is working. Please copy and run it on your computer.

import java.sql.*;

public class JDBCExample{ 

public static void main(String args[]) {
 try{
 Connection con;
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
 con=DriverManager.getConnection("jdbc:odbc:datastud"); 
 try{ 
    System.out.println("Getting All Rows from a table!"); 
    Statement st = con.createStatement(); 
    ResultSet res = st.executeQuery("SELECT * FROM college"); 
    System.out.println("studentcode: " + "\t" + "studentname: "); 
    while (res.next()) { 
        String i = res.getString("stud_code"); 
        String s = res.getString("stud_name"); 
        System.out.println(i + "\t\t" + s); 
    } 
    con.close(); 
    } catch (SQLException s){ 
      System.out.println("Error is:" + s.getMessage()); 
     }
    } catch (Exception e){ 
        System.out.println(e.getMessage());
        System.out.println("Error:connection not created"); 
    } 
    }
   }

Thanks


October 30, 2010 at 11:03 PM

Hi,

Please check the field stud_code in database. In my case it is Text type. So, I changed the code:

int i = res.getInt("stud_code");

into

String i = res.getString("stud_code");

Thanks


October 30, 2010 at 11:29 PM









Related Tutorials/Questions & Answers:
i cant find any compile time error but there is runtime error.
i cant find any compile time error but there is runtime error.  ... (res.next()) { int i = res.getInt("stud_code"); String s = res.getString("stud_name"); System.out.println(i + "\t\t" + s
plz check my codings are correct or not...There is an error..i cant find it..
plz check my codings are correct or not...There is an error..i cant find it..  import java.util.Scanner; public class Student { private String indexNo; private String gender; private char initial; private int mark1
Advertisements
compile time error
compile time error  my program compile successfully and make the class file also but when i tried to do next command to see the output,it showing error that "could not find or load main class fibbo" fibbo is my class name
compile time error
compile time error  my program compile successfully and make the class file also but when i tried to do next command to see the output,it showing error that "could not find or load main class fibbo" fibbo is my class name
compile time error
compile time error  my program compile successfully and make the class file also but when i tried to do next command to see the output,it showing error that "could not find or load main class fibbo" fibbo is my class name
Compile time error
Compile time error  Hi, When i compile my simple program in cmd am getting a error like "Javac is not a recognized as an internal or external command, operable program or batch file" How to resolve this problem ????  
Java compile time error. - Java Beginners
Java compile time error.  CreateProcess error=2, The system cannot find the file specified  Pleae Describe your query  Hi friend... technologies then i am sending you a link. This link will help you. Please visit
i got an error while compile this program manually.
i got an error while compile this program manually.  import... mapping.findForward("errors.jsp"); } } i set both servlet,struts jar files and i got an error in saveErrors() error Heading cannot find
compile error
program with Test.java and try to compile with javac test.java an error like...compile error  Hello All for example public class..."); } } i have save this program with A.java. Then I executed this program javac A.java
Runtime error
Runtime error  I have written 3n+1 code in java and it gives correct o/p but when i submit my code online for my contest it says runtime error.. how to know where is problem
runtime error
runtime error  still i am getting runtime error as:the specified dsn contains an architecture mismatch between the driver and application   Hi, This error is related to some OS related problem.ADS_TO_REPLACE_1 "dsn
Error : javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope
Error : javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope  I am getting following error in my struts-jsp proram for adding data to the database. 500 Internal Server Error
Compile error - Java Beginners
Compile error  I get this error when compiling my program: java:167... to be thrown tc.countLines(inFile); ^ 1 error... standards this will work since i put the bracket on the same line
Compile error - WebSevices
Compile error  Hello, How to read .pdf file using Javascript/php. Any one send the code
java runtime error - JDBC
java runtime error  when i m running my program using type1 driver it is showing a runtime error of SQLException of unable to create the connection object.please give the solution
when I run exiting project that time I got error, I want solution on it?
when I run exiting project that time I got error, I want solution on it?  Error occurred during deployment: Exception while loading the app... log for details. BUILD FAILED (total time: 1 minute 20 seconds
Java compile error - Java Beginners
Java compile error  I am having trouble compiling the Java project... Kindly let me know what is the problem? Secondly, do you know any easy method to compile Java on Mac besides using the Terminal
java runtime error - JDBC
java runtime error  when i m running my program by using jdk1.6.0 then it is giving the error of classunsupported major.minor version 50.0.to remove... version error 49.0.so, please suggest how will i compensate this problem
runtime error in java
runtime error in java  What is Run time error in Java?   Run time error is a syntax error that during the execution of a program.It hash different types of a program like as Logic error,Fatal Errors,source code,wrong
run time error
run time error  my program compile successfully but does not showing output for any program ...   Post your code.   public class... it doesn't showing any output. what should i do now?   Here it works
runtime error - Java Beginners
runtime error  I created a sample java source ,compiled it succesfully using command prompt but when i tried to run i got the folowing error " Exception in thread "main" java.lang.UnsupportedClassVersionError" I have set
runtime error - Java Beginners
runtime error  sir run time error is coming again in this code also null pointer Exception at for( File f:contents) import java.io.*; public class RecentDocumentsDelete { public static void main(String[] args) { String
java runtime error - JDBC
java runtime error  sir when i m running the jsp connectivity program it is giving the error as follows:' java.lang.NullPointerException at jsp_servlet.__resplogin._jspService(__resplogin.java:237
java runtime error - JDBC
java runtime error  when i am running my jdbc program using thin driver this error is coming at runtime: Exception in thread "main..., give me the suggesion yo solve this problem  This kind of error due
java run time error - Java Beginners
java run time error  when i compile my program it didnt show any error in my program.but i cant run my program, if i run my program means it will show error like as following Exception in thread "main
java runtime error - JDBC
java runtime error  when i m running my jdbc program it is giving the problem as class not found exception.so, please suggest me what may be the solution regarding this.  Hi friend, The problem is of Jar
java runtime error
java runtime error  hi friends i am trying to run the fallowing program but i am getting the error Exception in thread "main" java.lang.UnsupportedClassVersionError: JDBCCreateTab le (Unsupported major.minor version 50.0
Run time error - WebSevices
Run time error  Hello, Anyone know, how run the template files in zend framework.Anybody help me. Rgds, Pras  code to help in solving the problem : protected function _run($template
runtime error - Java Beginners
runtime error  import java.io.*; public class RecentDocumentsDelete { public static void main(String[] args) { String currentUser = System.getProperty("user.name"); System.out.println(currentUser
Error
Error  I have created ajax with php for state and city. When I change state then city will not come in dropdown list and it give me error as 'Unknown Runtime Error'. This error come only in IE browser, but in other brower
java run time error - JDBC
java run time error  when i m running for batch execution program in jdbc i m facing this kind of runtime error as Exception in thread "main...) at BatchUpdation.main(BatchUpdation.java:10) THE CODE WHICH I HAVE WRITTEN
Some error find whats the problem
Some error find whats the problem  import java.io.*; public class...=br.readline(); String str=" "; String st=" "; for(int i=0;i<=s.lenth();i++); { char ch=s.charAt(i); if(ch!=' ') { str=str+ch; { if(str.equals(w1)) { st
jsp runtime error - JSP-Servlet
jsp runtime error  sir, when i am running ur prog... from this website.... http://www.roseindia.net/jsp/poi/readingWriting.shtml i did the same as per guidelines...but i got error..!!!! org.apache.jasper.JasperException
Unknown runtime error in Ajax - Ajax
Unknown runtime error in Ajax  Getting Unknown runtime error in Ajax... error in Internet Explorer.Any once please give me the solution. Div tag: calling the Ajax: Add State Script
I GOT ERROR FOR MY PROJECT
I GOT ERROR FOR MY PROJECT  Dear Friend/ RoseIndia Team, Firstly I would to thank u Guys help me so many time.. I got error on my little project when running at server. please correctly my error Guys... ERROR CODE: "LOGIN
Error-
Error-   Hello, I would like to know about XSD file. I try to print XML file but I am getting error SAXException-- says Content is not allowed in prolog. Please help me
Error during runtime NoClassDefFound in java
; } } this gives NoClassDefFound error during runtime. i have done...Error during runtime NoClassDefFound in java  code: package Jama...++) { z = H[i][n-1]; H[i][n-1] = q * z + p * H[i][n
Error during runtime NoClassDefFound in java
; } } this gives NoClassDefFound error during runtime. i have done...Error during runtime NoClassDefFound in java  code: package Jama...++) { z = H[i][n-1]; H[i][n-1] = q * z + p * H[i][n
java runtime error - Java Beginners
java runtime error  sir, i have installed jdk in my system.i had also set path.But i am unable to run the compiled class file.it shows run time... friend, Please send source code and explain in detail. I am sending you
error
error  i have 404 error in my program plz tell me yhe solution about
error
error  i have 404 error in my program plz tell me yhe solution about
java runtime error - Java Beginners
java runtime error  import java.io.*; class Test { public static... int[s]; int i=0; System.out.println("Enter array elements"); for(i=0;ijava...) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316) Could not find the main class
jdbc run time error - JDBC
jdbc run time error  i m creating the table using thin driver it is showing the following run time error: Exception in thread "main...) at Jdbc14.main(Jdbc14.java:6) THE CODE WHICH I HAVE WRITTEN
java runtime error - Development process
java runtime error  I Migrated jdk1.3 to jdk1.4. after that my ftp clint not working.iam getting class not found exception fileinputstreem. i am using sun package. can any one send pure java code for FTP process i think jdk
error
error  I am running a program insert into statement in sql using.../ServletUserEnquiryForm.shtml getting an error given below SQLException caught: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error please suggest
Java Runtime error - Java Beginners
Java Runtime error  I have designed a simple chat application where the client and the server is the same computer itself. I have used the ipaddress.... I get this error: java.net.ConnectException: Connection refused: connect
error
error  When I deploye the example I have this message cannot Deploy HelloWorld Deployment Error for module: HelloWorld: Error occurred during deployment: Exception while deploying the app [HelloWorld
JDBC:Runtime error - Java Beginners
JDBC:Runtime error  Dear sir/madam i am facing a problem with jdbc program. When i run my program using NetBeans6.1 it is working fine. When i try to run the program from command prompt it is giving error. The follwing
Java runtime error - JSP-Servlet
Java runtime error  Following Error is showing when i way scanner.acquire() can any body help me please uk.co.mmscomputing.device.sane.SaneIOException: uk.co.mmscomputing.device.sane.SaneDeviceManager.getDevice
hi , i cant make this programmer , can any one help me to make it pls - Java Beginners
hi , i cant make this programmer , can any one help me to make it pls  ... program. i cant find delete records or update records  pls can..., salary, address... Practically, this software (set of classes) at excution time

Ads