Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException with ResourceBundle

 
Nirlep Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"discuss teaching",
Please check your Private Messages.

Thanks
Jeanne
JavaRanch Sheriff
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic