Home Answers Viewqa JDBC i cant find any compile time error but there is runtime error.

 
 


prathyu reddy
i cant find any compile time error but there is runtime error.
3 Answer(s)      2 years and 7 months ago
Posted in : JDBC

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 Pages:
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
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 ????  
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
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
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
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
Error during runtime NoClassDefFound in java
; } } this gives NoClassDefFound error during runtime. i have done...Error during runtime NoClassDefFound in java  code: package Jama... with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues, lambda
Error during runtime NoClassDefFound in java
; } } this gives NoClassDefFound error during runtime. i have done...Error during runtime NoClassDefFound in java  code: package Jama... with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues, lambda
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. "dsn contains
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
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
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
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
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
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
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
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
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
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 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 - 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
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
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 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
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 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
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
complier error - Java Beginners
Thanks  Hi Friend, Difference: Compile time error shows syntax... compile time and run time.  Hi Friend, Difference: Compile time error shows syntax errors like: required : int found : byte Runtime error
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
error
"+it); } } this is my program i am getting an error saying cannot find symbol class string
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
runtime error:Invalid column name
runtime error:Invalid column name  Hello, Can anyone please help me on this query? Programatically it is showing run time error. But in sql query the query is working fine. import java.sql.Connection; import
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 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
JDBC:Runtime error - Java Beginners
JDBC:Runtime error  Dear sir/madam, thanks to respond for my request. I tried as you said but still i facing the same problem no suitable drivers found for mysql. I copied the mysql-connector-jave-5.0.8-bin.jar, mysql-connector
Java error code
; Java Error code are the set of error that occurs during the compile-time and Run-time. From java error we have given  you a sample of code...) For removing this runtime error you have to specify the size of the Array
java runtime error: JDBC code - Java Beginners
java runtime error: JDBC code  Hi i want to insert data into mysql database in my local system. I installed mysql5.0 and using mm.mysql-2.0.4-bin.jar and also set in the class path. the code is compilled and giving runtime error
what is the error - Java Beginners
what is the error  What is the compile time error that i am getting... is creating the compile time error such as : - ? CANNOT FIND SYMBOL ? because you... the variable ? Private ? it will also create the error such as : ? CANNOT FIND
error in java progran at run time - Java Beginners
error in java progran at run time  Hello sir,,, i make a servlet program in java,,but i face some problem,,so please me.. Actually this type of error are come in my all servlet program My Servlet-- Error
error in java progran at run time - Java Beginners
error in java progran at run time  Hello sir,,, i make a servlet program in java,,but i face some problem,,so please me.. Actually this type of error are come in my all servlet program My Servlet-- Error
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
Getting an error :(
Getting an error :(  I implemented the same code as above.. But getting this error in console... Console Oct 5, 2012 10:18:14 AM...:SpringMVC' did not find a matching property. Oct 5, 2012 10:18:14 AM
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
Compiling Error - Java Beginners
Compiling Error  cant able to compile java servlet file in the command prompt? WHY? but i can compile normal java file give me answer to fix my problem
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.