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



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

Have Programming Question? Ask it here!
 
 
 


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


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
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
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
hi - JDBC
jdbc connectivity steps java  Need steps for JDBC Connectivity. Thanks
hi - JDBC
JDBC connection pool  What is connection pooling 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
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
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
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
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
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
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
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
can i Execute PHP code inside python script?
can i Execute PHP code inside python script?    can i Execute PHP code inside python script
How can I execute a PHP script using command line?
How can I execute a PHP script using command line?  How can I execute a PHP script using command line
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
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
Learning Ajax
Learning Ajax  Hi, I have experience in web web application development. But I am new in Ajax programming. How I can learn Ajax? Thanks   Hi, Please check the thread Learning Ajax. Thanks
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
Learning Java
Learning Java  Hi, How is the process of Learning Java is difficult? I have heard that Java is very difficult language. Let's know your comments. Thanks   Hi, Java is easy language. You can even Learn Java in a Day
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
how to execute a unix shell script from a java program
how to execute a unix shell script from a java program  well , i am facing this problem.. i have tried a few sample codes but there isn't any... the script name from a java code .once you execute this java program
Learning Ajax
Script program. After learning Javascript you should learn more details about...Learning Ajax  How to learn Ajax? Thanks   If you are web... Ajax. How I can learn Ajax? You can learn ajax programming language very easily
Hi..Date Program - Java Beginners
Hi..Date Program  Hi Friend...thank for ur Valuable information... Its displaying the total number of days.. but i WANT TO DISPLAY THE NUMBER OF DAYS BY EACH MONTH...   Hi friend, Code to solve the problem
learning java
learning java  Am learning java. but i feel really confusing about the topics like objects and classes. some times the objects are referred as the instance of a class but when comes the hierarchy, there comes the topic like
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
error in program when trying to load image in java - Java Beginners
error in program when trying to load image in java  Hi, I'm trying... below is the codes I used to create a logo. Once I tried to run the program I got... errors but my program still won't run. I keep getting this type of message and I
Hi ..I am Sakthi.. - Java Beginners
Hi ..I am Sakthi..  can u tell me Some of the packages n Sub Directories starts with... import javax.swing.*; import javax._________;  ...;Hi friend, package javacode; import javax.swing.*; import
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import... to the libraries.the pdf file are not opened when i execute the program.please send the code to open the pdf file when i execute the jsp page
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import... to the libraries.the pdf file are not opened when i execute the program.please send the code to open the pdf file when i execute the jsp page
 

 

 

DMCA.com