NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Having problems with Java DB

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Developers
View previous topic :: View next topic  
Author Message
royacle



Joined: 05 Feb 2012
Posts: 4
Location: India

PostPosted: Sun Feb 05, 2012 7:53 am    Post subject: Having problems with Java DB Reply with quote

Please I need help with my Final year college project, am alone on it and have very little experience with Netbeans. I problems with my login and signup pages. They're always returning an exception whenever I try to either login or create a new . Below are the codes. Thanks in advance

Login.java


package examhome;

import java.sql.*;
import javax.swing.JOptionPane;
public class Login extends javax.swing.JFrame {

Connection conn;
PreparedStatement pstmt;

public Login() {
initComponents();
try
{
//Class.forName("sun:jdbc:odbc:JdbcOdbcDriver");
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
//conn=DriverManager.getConnection("jdbc:odbc:royacle","admin","admin");
//conn=DriverManager.getConnection("jdbc:derby://localhost:1527/royacle;user=admin;password=admin");
conn=DriverManager.getConnection("jdbc:derby://localhost:1527/royacle[admin on ADMIN]");
}
catch(ClassNotFoundException e)
{
System.out.println("class not exception");
}
catch(SQLException e)
{
System.out.println("sql exception");
}
setVisible(true);
}


private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jPasswordField1.setText("");// TODO add your handling code here:
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
String str=evt.getActionCommand();
if(str.equals("SIGN UP"))
{
//SignUp page=new SignUp.SignUP();
SignUp signUp = new SignUp();
setVisible(false);


}

}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String str=evt.getActionCommand();
String value1=jTextField1.getText();
String value2=jPasswordField1.getText();
String a="";
String b="";
if(str.equals("LOGIN"))
{


try
{

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");


pstmt=conn.prepareStatement("select * from register");
conn=DriverManager.getConnection("jdbc:derby://localhost:1527/royacle[admin on ADMIN]");
Statement ss=conn.createStatement();
ResultSet rs=pstmt.executeQuery();


//if(rs.next())
int flag=0;
while(rs.next())
{
a=rs.getString("username");
b=rs.getString("password");

if(value1.equals("") && value2.equals(""))
{
JOptionPane.showMessageDialog(null,"Please enter a username & password","Error",JOptionPane.PLAIN_MESSAGE);
}

else if(value1.equals(a) && !value2.equals(b))
{
JOptionPane.showMessageDialog(null,"Wrong username or password, try again","Error",JOptionPane.PLAIN_MESSAGE);
}
else if(value1.equals(a) && value2.equals(b))
{
flag=1;
userHome page=new userHome();
setVisible(false);
dispose();

}
}
}
catch(ClassNotFoundException e)
{
System.out.println("class not exception");
}
catch(SQLException e)
{
System.out.println("sql exception");
}
setVisible(true);// TODO add your handling code here:
}
}

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {

@Override
public void run() {
new Login().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}

========================================
SignUp.java

package examhome;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JOptionPane;



public class SignUp extends javax.swing.JFrame {


PreparedStatement pstmt;
Connection conn;
public SignUp() {
initComponents();


try
{
//Class.forName("sun:jdbc:odbc:JdbcOdbcDriver");
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
//conn=DriverManager.getConnection("jdbc:odbc:royacle","admin","admin");
//conn=DriverManager.getConnection("jdbc:derby://localhost:1527/royacle;user=admin;password=admin");
conn=DriverManager.getConnection("jdbc:derby://localhost:1527/royacle[admin on ADMIN]");
}
catch(ClassNotFoundException e)
{
System.out.println("class not exception");
}
catch(SQLException e)
{
System.out.println("sql exception");
}
setVisible(true);
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jPasswordField1.setText("");
jPasswordField2.setText("");
jTextField7.setText("");// TODO add your handling code here:
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String s=evt.getActionCommand();
Object obj=evt.getSource();
if(jTextField5.equals("") && jPasswordField1.equals(""))
{
JOptionPane.showMessageDialog(null,"Please fill the form properly","Error",JOptionPane.PLAIN_MESSAGE);
}
else if(s.equals("SAVE"))
{
try
{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

conn=DriverManager.getConnection("jdbc:derby://localhost:1527/royacle[admin on ADMIN]");
pstmt=conn.prepareStatement("insert into register values(?,?,?,?,?,?,?,?,?)");

String Fname=jTextField1.getText();
pstmt.setString(1,Fname);

String Lname=jTextField2.getText();
pstmt.setString(2,Lname);

String Address=jTextField3.getText();
pstmt.setString(3,Address);

String Major=jTextField4.getText();
pstmt.setString(4,Major);

String username=jTextField5.getText();
pstmt.setString(5,username);

String dob=jTextField6.getText();
pstmt.setString(6,dob);

String password=jPasswordField1.getText();
pstmt.setString(7,password);

String cpassword=jPasswordField2.getText();
pstmt.setString(8,cpassword);

String email=jTextField7.getText();
pstmt.setString(9,email);
pstmt.executeUpdate();

}
catch(ClassNotFoundException e)
{
System.out.println("class not exception1");
}
catch(SQLException se)
{
JOptionPane.showMessageDialog(this,"Error in saving file","Royal Premuim App",JOptionPane.PLAIN_MESSAGE);
}
JOptionPane.showMessageDialog(this,"Succesful registration","Royal Premium App",JOptionPane.PLAIN_MESSAGE);

jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jPasswordField1.setText("");
jPasswordField2.setText("");
jTextField7.setText("");

}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String str=evt.getActionCommand();
if(str.equals("GO TO LOGIN"))
{
//Login page=new Login();
Login login=new Login();
setVisible(false);
// TODO add your handling code here:
}


}
public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

@Override
public void run() {
new SignUp().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JPasswordField jPasswordField2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
// End of variables declaration
}
Back to top
bolsover



Joined: 24 Jun 2010
Posts: 185

PostPosted: Sun Feb 05, 2012 4:00 pm    Post subject: Reply with quote

What exception is being thrown - and when?
Back to top
royacle



Joined: 05 Feb 2012
Posts: 4
Location: India

PostPosted: Mon Feb 06, 2012 7:12 am    Post subject: Reply with quote

Problem 1: When I run it using java -jar ExamHome.jar, it shows "class not exception". But the login page comes up.

Problem 2: When I click the "sign up" button, it shows "class not exception" but goes on to load the "Signup" form.

Problem 3: When I fill out the signup form and click save it returns a message of success but nothing is written to Java DB. And shows "class not exception1"

Problem 4: I entered entries manually into the database and tried login in with it returns the exception "class not exception".

So I can't be redirected into the next page of userHome.java.

thanks in advance. If you need me to send you the full code then I can do so.
Back to top
bolsover



Joined: 24 Jun 2010
Posts: 185

PostPosted: Tue Feb 07, 2012 2:34 pm    Post subject: Reply with quote

As a first step, I suggest you replace System.out.println("class not exception"); (and other exception handling) with System.out.println(e.printStackTrace());. The output should help identify where the problem is.

My best guess is that org.apache.derby.jdbc.EmbeddedDriver is not on the classpath.
Back to top
royacle



Joined: 05 Feb 2012
Posts: 4
Location: India

PostPosted: Tue Feb 14, 2012 6:09 am    Post subject: Reply with quote

Thanks bolsover, I'd try to do so ASAP but I don't know how to do the classpath thing could please guide me? Am still very new to netbeans and java GUI coding. And once am done I'll inform you of my plight. So sorry was off for a very long time lost someone in death.
Back to top
royacle



Joined: 05 Feb 2012
Posts: 4
Location: India

PostPosted: Sat Feb 18, 2012 10:51 am    Post subject: Reply with quote

hello bolsover,

After doing as you advised here's the error generated and don't seem to get it well. The only thing I understand is that there's a driver issue. I tried changing the driver to Embedded but the same error comes up.



java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at Login.Login.jButton1ActionPerformed(Login.java:205)
at Login.Login.access$000(Login.java:12)
at Login.Login$1.actionPerformed(Login.java:89)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6288)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6053)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4651)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:9Cool
at java.awt.EventQueue$2.run(EventQueue.java:616)
at java.awt.EventQueue$2.run(EventQueue.java:614)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Developers All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo