• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

ClassNotFoundException with ResourceBundle

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"discuss teaching",
Please check your Private Messages.

Thanks
Jeanne
JavaRanch Sheriff
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic