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

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
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
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
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?"
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
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
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
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
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
Java NullPointerException
class. NullPointerException must bethrown when an application attempts... Java NullPointerException       NullPointerException is a kind of unchecked exception
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
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 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
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
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
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
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
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
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

Ads