473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

What is the fault in this code

Expand|Select|Wrap|Line Numbers
  1.  
  2. package librarySystemV5;
  3. import java.sql.*;
  4. import java.util.*;
  5.  
  6. public class DatabaseTableViewer {
  7.    private static final String DB = "mytestdb",
  8.                                TABLE_NAME = "MEMBER",
  9.                                HOST = "jdbc:mysql://db_host:3306/",
  10.                                ACCOUNT = "dbadmin",
  11.                                PASSWORD = "dbadmin",
  12.                                DRIVER = "jdbc:mysql://localhost:3306/";
  13.  
  14.    public static void main (String[] args) {
  15.       try {
  16.  
  17.          // authentication properties
  18.          Properties props = new Properties();
  19.          props.setProperty("user", ACCOUNT);
  20.          props.setProperty("password", PASSWORD);
  21.  
  22.          // load driver and prepare to access
  23.          Class.forName(DRIVER).newInstance();
  24.          Connection con = DriverManager.getConnection(
  25.             HOST + DB, props);
  26.          Statement stmt = con.createStatement();
  27.  
  28.          // execute select query
  29.          String query = "SELECT * FROM " + TABLE_NAME + ";";
  30.          ResultSet table = stmt.executeQuery(query);
  31.  
  32.          // determine properties of table
  33.          ResultSetMetaData meta = table.getMetaData();
  34.          String[] colNames = new String[meta.getColumnCount()];
  35.          Vector[] cells = new Vector[colNames.length];
  36.          for( int col = 0; col < colNames.length; col++) {
  37.             colNames[col] = meta.getColumnName(col + 1);
  38.             cells[col] = new Vector();
  39.          } 
  40.  
  41.          // hold data from result set
  42.          while(table.next()) {
  43.             for(int col = 0; col < colNames.length; col++) {
  44.                Object cell = table.getObject(colNames[col]);
  45.                cells[col].add(cell);
  46.             }
  47.          }
  48.  
  49.          // print column headings
  50.          for(int col = 0; col < colNames.length; col++)
  51.             System.out.print(colNames[col].toUpperCase() + "\t");
  52.          System.out.println();
  53.  
  54.          // print data row-wise
  55.          while(!cells[0].isEmpty()) {
  56.             for(int col = 0; col < colNames.length; col++) 
  57.                System.out.print(cells[col].remove(0).toString() 
  58.                                    + "\t");
  59.             System.out.println();
  60.          }
  61.       }
  62.  
  63.       // exit more gently
  64.       catch(Exception e) {
  65.          e.printStackTrace();
  66.       }
  67.    }
  68. }
  69.  
  70.  
  71.  

I got erorr like this

[HTML]
java.lang.ClassNotFoundException: jdbc:mysql://localhost:3306/
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at librarySystemV5.DatabaseTableViewer.main(DatabaseT ableViewer.java:22)


[/HTML]



I used Eclipse IDE,

Please any body help me, This is for reading the data from table and print the out put on console witht the propper table styles.
Mar 2 '08 #1
6 1483
JosAH
11,448 Expert 8TB
[HTML]
java.lang.ClassNotFoundException: jdbc:mysql://localhost:3306/
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at librarySystemV5.DatabaseTableViewer.main(DatabaseT ableViewer.java:22)


[/HTML]

I used Eclipse IDE,

Please any body help me, This is for reading the data from table and print the out put on console witht the propper table styles.
Please don't double post; I have removed your other identical thread. About your
problem: as the error diagnostic message indicates: the jvm can't find the class
"jdbc:mysql://localhost:3306". That is not a class name, it's a URL used to
establish a connection. You have to load the driver class first. Check your
documentation.

kind regards,

Jos (mod)
Mar 2 '08 #2
Thanks Joe, while I working time my net connection failed, So I post another time too.

I need to print the console out put witht he tabular alignment, mean to put the out put each column should be come under the line by line

Like that, But My Screen Out does not coming on those way, all the values are intermixing.

So, Please to help me.
Regards,
Joshep
Mar 2 '08 #3
Thanks Joe, while I working time my net connection failed, So I post another time too.

I need to print the console out put witht he tabular alignment, mean to put the out put each column should be come under the line by line

Like that, But My Screen Out does not coming on those way, all the values are intermixing.

So, Please to help me.
Regards,
Joshep

I couldnt add my actual format on here, because it is also showing as my mixxing outpt like.
TablCol1 TableCol2
Value 1 1 Value2 2
Mar 2 '08 #4
JosAH
11,448 Expert 8TB
I couldnt add my actual format on here, because it is also showing as my mixxing outpt like.
TablCol1 TableCol2
Value 1 1 Value2 2
So your first problem is automagically solved? For this little problem add spaces
to the column names and values so they neatly line up when printed.

kind regards,

Jos
Mar 2 '08 #5
So your first problem is automagically solved? For this little problem add spaces
to the column names and values so they neatly line up when printed.

kind regards,

Jos

Yes, JosAH

You got my view.
Mar 3 '08 #6
Yes, JosAH

You got my view.

Thank you I got it

Using like that code.
int N=2;
System.out.format("% 5d", N);
Mar 3 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Niklaus | last post by:
Hi, Can someone point out what is wrong with this code ? How can i make it better optimize it. When run it gives me seg fault in linux. But windows it works fine(runs for a long time). Do we...
3
by: I_have_nothing | last post by:
Hi! I am new in C. I got a lots of "Segmentation Fault"s in my code. I guess One possibility is: if " int array_i; " is declard and the code trys to access "array_i", a Segmentation Fault will...
6
by: I_have_nothing | last post by:
Hi! I am new in C. I try to use dynamical allocation fuction malloc( ) and realloc( ). I found something strange. After several calling realloc( ), the malloc( ) will give me a Segmentation...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
0
by: Matt S | last post by:
Hello, I'm trying to build a C# client to consume an AXIS Web Service (running SOAP over HTTP). The Web Service encodes full server-side exception traces in the Soap Fault > Detail element...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
8
by: lawrence k | last post by:
We made some changes to our server yesterday, and ever since, every single installation of WordPress that was on the server has stopped running. Other PHP scripts still run fine, but WordPress is...
7
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our...
0
by: Equinex | last post by:
Hi, I am trying to call a Web Service using Php and Soap. Why does the following Php 5 code return? try { //$ExchangeLoginResult = $ExchangeClient->Login(array("request" =>
2
by: Nagaraj | last post by:
Hi all, I am new to Linux platform. I am writing some C programs on Linux platform. It gives the segmentation fault error, what is segmentation fault and how to remove it. please reply.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.