Nitin Kumar
hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.
1 Answer(s)      4 years and 8 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

Advertisement
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
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
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
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
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
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
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
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
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
hi - JDBC
jdbc connectivity steps java  Need steps for JDBC Connectivity. Thanks
hi - JDBC
JDBC connection pool  What is connection pooling in JDBC
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
Java NullPointerException
class. NullPointerException must bethrown when an application attempts... Java NullPointerException       NullPointerException is a kind of unchecked exception
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
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
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
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 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 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
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
i got illegal start of expression error , plese tell me the mistake where i did...
i got illegal start of expression error , plese tell me the mistake where i did...   import org.springframework.context.*; import java.util.*; public class MyListener implements ApplicationListener { public static void main
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
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
NullPointerException - EJB
as per my jboss directory. I got the EAR file created succesfully when i run the buil.xml. When i call "http://localhost:8080/example" i got the Welcome page...NullPointerException  Hi, I tried to deploy the "CalculatorBean
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 program
jdbc program   Write a program to update the salaryRs.6000/- for an employee name like ‚??P. Ramu‚?? using prepared statement
Advertisement