GeeCON Prague 2014*
The moose likes JDBC and the fly likes ClassNotFoundException with ResourceBundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "ClassNotFoundException with ResourceBundle" Watch "ClassNotFoundException with ResourceBundle" New topic
Author

ClassNotFoundException with ResourceBundle

Nirlep Patel
Greenhorn

Joined: Jul 29, 2007
Posts: 7
Dear friends

I am using NetBeans IDE 5.5 and facing problem in Database Connectivity using ResourceBundle Class.


This is the Code of Main.java:


package resobundledb;
import java.sql.* ;
import java.util.*;

public class Main {

public static void main(String argv[]) {
Connection con = null;
//ResultSet rs;
ResourceBundle bundle = ResourceBundle.getBundle ("dbresource");
System.out.println("Hello this is resourcebundle database connectivity 01");
System.out.println();

try{

String url = bundle.getString ("URL");
System.out.println("url is: " + url);
Statement stmt;
ResultSet rs;

System.out.println("Driver is: " + bundle.getString ("Driver"));
/* Load the Driver Class. */ Problem is here
Class.forName(bundle.getString("Driver")); -Problem is here
//Class.forName(java.util.ResourceBundle
.getBundle("resobundledb/dbresource") .getString("Driver"));

System.out.println("Hello this is resourcebundle database connectivity 02");
//here is where the connection is made
con = DriverManager.getConnection(url, java.util.ResourceBundle .getBundle("resobundledb/dbresource") .getString("root"), java.util.ResourceBundle .getBundle ("resobundledb/dbresource") .getString("nipatel"));
//con = DriverManager.getConnection(url, "root", "nipatel");
System.out.println("Hello this is resourcebundle database connectivity 03");
stmt = con.createStatement();

//rs = stmt.executeQuery(java.util.ResourceBundle .getBundle("resobundledb/dbresource") .getString("select_*_from _tbluser"));
rs = stmt.executeQuery("select * from tbluser");

System.out.println("This is the result: ");
System.out.println();

while(rs.next()){
//int uid = rs.getInt("uid");
int uid = rs.getInt(1);

//String username = rs.getString("username");
String username = rs.getString(2);

//String name = rs.getString("name");
String name = rs.getString(4);

//String bdate = rs.getString("birthdate");
String bdate = rs.getString(5);

//double sscper = rs.getDouble("sscpercentage");
double sscper = rs.getDouble(6);

//double fees = rs.getDouble("fees");
double fees = rs.getDouble(7);

//String lastaccesstime = rs.getString("lastaccessedtime");
String lastaccesstime = rs.getString(8);

System.out.println("User id: " + uid);
System.out.println("User Name: " + username);
System.out.println("Name: " + name);
System.out.println("Birth Date: " + bdate);
System.out.println("SSC Percentage: " + sscper + " %");
System.out.println("Fees: " + "Rs. " + fees);
System.out.println("Last Accessed Time: " + lastaccesstime);
}
stmt.close();
}
catch( SQLException e ) {
System.out.println("it is printing from SQLException");
e.printStackTrace();
}
catch(ClassNotFoundException e){
System.out.println("it is printing from ClassNotFoundException");
System.out.println(e.getMessage());
}
finally {
if( con != null ) {
try { con.close(); }
catch( Exception e ) { }
}
}
}
}
------------------------------ ------------------------------ ------------------------------ ------------------------------ --------------

This is my dbresource.properties file

Driver=com.mysql.jdbc.Driver
URL=jdbc:mysql://localhost :3306/test
select_*_from_tbluser=select * from tbluser
nipatel=nipatel
root=root

------------------------------ ------------------------------ ------------------------------ ------------------------------ --------------

This is my Database columns in MySQL

Column

Datatype
userid

int(11)
username

varchar(8)
password

varchar(8)
name

varchar(60)
birthdate

Date
sscpercentage

double(4,2)
fees

double(8,2)
lastaccessedtime

Date

------------------------------ ------------------------------ ------------------------------ ------------------------------ --------------

Output should be in this format

Userid: 1
Username: elitecore
Name: Elitecore
Birth date: 1st January, 2003
SSC Percentage: 88.1 %
Fees: Rs. 700.50
Last accessed time: 1st Jan 2003, 11:00 am



--
Regards
Nirlep


regards, nirlep
discuss.teaching@gmail.com, http://www.learnclinux.com
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

"discuss teaching",
Please check your Private Messages.

Thanks
Jeanne
JavaRanch Sheriff


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Please don't post the same question in multiple forums. It creates duplicate conversations and wastes the time of the people trying to help you.

Thanks,
Dave
 
Don't get me started about those stupid light bulbs.
 
subject: ClassNotFoundException with ResourceBundle