I tried to get the data from my database name as jaane with user name Hello and Password hello. Error:
java.lang.SecurityException: Prohibited package name: java
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:480)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: java.Main. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
my code is
package java;
import java.awt.Container;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/**
*
* @author ritesh
*/
public class Main extends JFrame{
public Main() throws SQLException
{super("Database of Students");
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Connection connection = DriverManager.getConnection( "jdbc:derby:/localhost:1527","hello","Hello" );
Statement statement = connection.createStatement();
// query database
ResultSet resultSet =
statement.executeQuery( "SELECT * FROM COLLEAGUES" );
StringBuffer results = new StringBuffer();
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
for ( int i = 1; i <= numberOfColumns; i++ ) {
results.append( metaData.getColumnName( i ) + "\t" );
}
results.append( "\n" );
while ( resultSet.next() ) {
for ( int i = 1; i <= numberOfColumns; i++ ) {
results.append( resultSet.getObject( i ) + "\t" );
}
}
// close statement and connection
statement.close();
connection.close();
// set up GUI and display window
JTextArea textArea = new JTextArea( "Hello");
Container container = getContentPane();
container.add( new JScrollPane( textArea ) );
setSize( 300, 100 ); // set window size
setVisible( true ); // display window
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
Main window = new Main();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// TODO code application logic here
} catch (SQLException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}