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 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

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









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
When should I start learning machine learning?
When should I start learning machine learning?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: When should I start learning machine learning? Try to provide me good
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
What must I know before learning JDBC?
What must I know before learning JDBC?  Hi, I learned basic Java and want to learn JDBC. What must I know before learning JDBC? Thanks   ... and searching database from database. What must I know before learning JDBC? You must
What must I know before learning JDBC?
What must I know before learning JDBC?  Hi, I learned basic Java and want to learn JDBC. What must I know before learning JDBC? Thanks   ... and searching database from database. What must I know before learning JDBC? You must
What must I know before learning JDBC?
What must I know before learning JDBC?  Hi, I learned basic Java and want to learn JDBC. What must I know before learning JDBC? Thanks   ... and searching database from database. What must I know before learning JDBC? You must
What must I know before learning JDBC?
What must I know before learning JDBC?  Hi, I learned basic Java and want to learn JDBC. What must I know before learning JDBC? Thanks   ... and searching database from database. What must I know before learning JDBC? You must
Why is everyone Machine Learning?
Why is everyone Machine Learning?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Why... so that I can learn the topic "Why is everyone Machine Learning?"
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
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
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
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
hi - JDBC
JDBC connection pool  What is connection pooling in JDBC
hi - JDBC
jdbc connectivity steps java  Need steps for JDBC Connectivity. Thanks
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
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
When should I learn tensorflow
When should I learn tensorflow  Hi, TensorFlow is now getting used in industry. I am planning to learn it. When should I learn tensorflow? Thanks   Hi, Its always better to learn new technologies asap. Science
When should I learn tensorflow
When should I learn tensorflow  Hi, TensorFlow is now getting used in industry. I am planning to learn it. When should I learn tensorflow? Thanks   Hi, Its always better to learn new technologies asap. Science
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
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
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
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
machine learning online program
machine learning online program  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: machine learning online program Try to provide me good examples or tutorials links so
deep learning certificate program
deep learning certificate program  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: deep learning certificate program Try to provide me good examples or tutorials links
machine learning executive program
machine learning executive program  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: machine learning executive program Try to provide me good examples or tutorials
machine learning basic program
machine learning basic program  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: machine learning basic program Try to provide me good examples or tutorials links so
deep learning nanodegree program
deep learning nanodegree program  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: deep learning nanodegree program Try to provide me good examples or tutorials links
pg program in machine learning
pg program in machine learning  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: pg program in machine learning Try to provide me good examples or tutorials links so
Hi i want java code that diaplays server scren at the client side
Hi i want java code that diaplays server scren at the client side  Hi I'm Shivaprasad i want java socket code that shows the server side screen when client gets connected with the server. Please help me   Please visit
jdbc program
jdbc program   Write a program to update the salaryRs.6000/- for an employee name like â??P. Ramuâ?? using prepared statement
How do I start learning machine learning?
How do I start learning machine learning?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: How do I start learning machine learning? Try to provide me good examples
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...   // these image that put in program must be in the same folder that saved the program
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
Find a project or skill I am interested in learning
Find a project or skill I am interested in learning  Hi, I am... = window.adsbygoogle || []).push({}); Thanks   Hi, I am giving you... played around with some code is: I leaned Java and then Python during my learning
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
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
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
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
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
Program compiles but won't execute - Java Beginners
Program compiles but won't execute  I have to write a program with a class Employee and then write a driver class to run it. This is what I have so far for the Employee class(it compiles but does not execute); public class
execution of a jdbc program
execution of a jdbc program  how to execute a servlet program that..uses a jdbc driver (i.e. using mysql-connector -java )to connect to mysql in windows *PLS provid the execution steps in detail THANK YOU
Null value when i set interface object in form controller - Spring
Null value when i set interface object in form controller   Hi all, i am very new about spring and hibernate. i got null value when i set.... when i call this method in form controller ohbillManager.saveBill(ohbill); i

Ads