Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  
 

hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.

Ads

 
 

Share on Google+Share on Google+

Nitin Kumar
hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.
1 Answer(s)      5 years and 11 months ago
Posted in : JDBC

ConnectionProvider.java import java.util.*; import java.io.*; import java.sql.*; class ConnectionProvider { static Properties prop; static { prop=new Properties(); try { prop.load(new FileInputStream("db.Properties")); }catch(Exception e) { System.out.println(e); } } public static Connection getConnection() { Connection con=null; try { Class.forName(prop.getProperty("driver class")); con=DriverManager.getConnection(prop.getProperty("url"),prop.getProperty("user"),prop.getProperty("password")); }catch(Exception e) { System.out.println(e); } return con; }

}

Selecttest1.java

import java.sql.*; class SelectTest1
{ public static void main(String arr[]) { try { Connection con=ConnectionProvider.getConnection(); System.out.println("name of Connection class is:"+con.getClass().getName()); Statement stmt=con.createStatement(); System.out.println("name of statement class is:"+stmt.getClass().getName()); ResultSet rset=stmt.executeQuery("select * from emp"); System.out.println("Name of resultset Class is:"+rset.getClass().getName()); System.out.println("following record are selected"); while(rset.next()) { System.out.println(rset.getInt(1)+"\t"+rset.getString(2)+"\t"+rset.getString(3)+"\t"+rset.getInt(4)); } }catch(Exception e) { System.out.println(e); } } }

And db.properties Class

driver class=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@localhost:1521:xe user=system pasword=oracle

Ads
View Answers

September 26, 2011 at 6:02 PM


It seems that problem lies in reading a properties file.

Go through the following link:

http://www.roseindia.net/tutorial/java/core/propertiesFile.html


Ads









Related Tutorials/Questions & Answers:
hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.
hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.   ConnectionProvider.java import java.util.*; import... class=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@localhost:1521:xe user
i got an error while compile this program manually.
i got an error while compile this program manually.  import...,struts jar files and i got an error in saveErrors() error Heading cannot find... ActionForward execute(ActionMapping mapping
Advertisements
I got build failed when deploying enterprise application - EJB
I got build failed when deploying enterprise application  I created web application with ejb moduless and stateless session beans. However, i am...;Hi friend, Please explain in detail, and send me code. Visit for more
How do I do this program? I'm new to Java programming...
How do I do this program? I'm new to Java programming...  Suppose you want to print out numbers in brackets, formatted as follows: [1] [2] [3] and so on. Write a method that takes two parameters: howMany and lineLength
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 : java.lang.IllegalStateException: ContainerBase.addChild: start
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP  as i said i want to create 3 drop dropdown list each depend on the other and get the options from
get UnsatisfiedLinkError when I try to use my JDBC driver.
get UnsatisfiedLinkError when I try to use my JDBC driver.  Why do I get UnsatisfiedLinkError when I try to use my JDBC driver
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
nullpointerException
nullpointerException  sir i create the on login module in that mysql generate the nullpointerException? please send login mdule code in jsp and servlet using mvc model?   Please visit the following link: Jsp Servlet
Simple java program
Simple java program Hi this is the thing we got to do and i am totally confused on how to write this program it would be a great help i could be helped. For the part 1 i got it but the second part how do you start writing
hi - JDBC
JDBC connection pool  What is connection pooling in JDBC
hi - JDBC
jdbc connectivity steps java  Need steps for JDBC Connectivity. Thanks
NullPointerException - SQL
NullPointerException  Greeting Everyone. I got NullPointerException when try to run UPDATE query. Here's the code where JSP dies: String short... sql string to make double check that query is correct. and when I try to run
steps required to execute a query in JDBC
steps required to execute a query in JDBC  What are the steps required to execute a query in JDBC
i got an exception while accept to a jsp
i got an exception while accept to a jsp  type Exception report message description The server encountered an internal error... in a file.later i changed it to ANSII problem is resolved
How can java programs execute automatically when it connects to network
How can java programs execute automatically when it connects to network  Good Day dears... How can java programs execute automatically when it connects to network. Thanks in Advance friends Shackir   How can i Test
Java NullPointerException
class. NullPointerException must bethrown when an application attempts... Java NullPointerException       NullPointerException is a kind of unchecked exception
hi
hi   I have connected mysql with jsp in linux and i have used JDBC connectivity but when i run the program, its not working the program is displaying
How do I start learning MongoDB?
How do I start learning MongoDB?  Hi, What are the correct steps of learn MongoDB? How do I start learning MongoDB? What is MongoDB and how I can learn? Thanks   Hi, MongoDB is one of several NoSQL database in world
JDBC Execute Statement
JDBC Execute Statement       JDBC Execute Statement is used to execute SQL Statement, The Execute... a database. In this Tutorial, the code illustrates an example from JDBC Execute
if i run this prog, i got exeption in thread "main" java.lang.ArrayIndexOutOfBoundsException:0 at Maxof2.main(Maxof2.java:9), whats the resolution for ths?
if i run this prog, i got exeption in thread "main... System.out.println(j+" is greater than "+i); } }   Hi Friend... When you will execute your code with the above statement then you will get
JDBC Execute Update Example
JDBC Execute Update Example       JDBC... a simple example from JDBC Execute update Example. In this Tutorial we want to describe you a code that helps you in understanding JDBC Execute update Example
JDBC Execute Query
JDBC Execute Query       The  Execute Query in JDBC retrieve the elements from a database. In this Tutorial we want to describe you a code that helps you to understand JDBC Execute Query
jdbc program
jdbc program   Write a program to update the salaryRs.6000/- for an employee name like ‚??P. Ramu‚?? using prepared statement
Jdbc and Socket Program - JDBC
Jdbc and Socket Program  Sir, I would like to get a program i... in a database.Now we create another program 4 client-server such that the sever's database is updated everytime we enter username and password in client program
i have got error while compiling simple tag handler
i have got error while compiling simple tag handler   javac.servlet.jsp not found! tell me what are the jar files required to run simple tag handler class   The package you have used javac.servlet.jsp does not exist
Jsp error when i run this a jsp file
Jsp error when i run this a jsp file  hi I got this error when i run the jsp file in IDE and outside also please help me java.lang.NullPointerException org.apache.jsp.insertjsp.jspInit(insert_jsp.java:22
Execute the java program using one processor
Execute the java program using one processor   Write a program... in dual core computer a) Execute the program using one processor b) Execute the program using more than one processor
use JDBC to execute non-standard features that my DBMS provides.
use JDBC to execute non-standard features that my DBMS provides.  Can I use JDBC to execute non-standard features that my DBMS provides
What is the return type of execute mehtod in jdbc - Java Beginners
What is the return type of execute mehtod in jdbc  Hi Deepak, u.... My interview asked wat is return type of execute() in jdbc . should i say boolean or Statement   Hi friend
java program - JDBC
java program  i have a DBschema, in that i have schema name and set of tables as fields, in this case i have three tables, i need a java program... out. i have used mysql for connecting to the database.  Hi friend