Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


prathyu reddy
i cant find any compile time error but there is runtime error.
3 Answer(s)      4 years and a month 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"); }


Advertisement
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. "dsn contains
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
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
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
Compile error - WebSevices
Compile error  Hello, How to read .pdf file using Javascript/php. Any one send the code
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
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
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
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
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
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
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 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 - 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
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 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
Advertisements
 

 

 

DMCA.com