Click here to Skip to main content
15,903,175 members
Home / Discussions / Java
   

Java

 
QuestionLogin process Always false..cannot find the error Pin
mali_angel3-Jul-13 18:16
mali_angel3-Jul-13 18:16 
AnswerRe: Login process Always false..cannot find the error Pin
Shubhashish_Mandal3-Jul-13 19:53
professionalShubhashish_Mandal3-Jul-13 19:53 
QuestionLogin process Always false..cannot find the error Pin
mali_angel3-Jul-13 17:22
mali_angel3-Jul-13 17:22 
AnswerRe: Login process Always false..cannot find the error Pin
mali_angel3-Jul-13 17:28
mali_angel3-Jul-13 17:28 
AnswerRe: Login process Always false..cannot find the error Pin
Shubhashish_Mandal3-Jul-13 19:40
professionalShubhashish_Mandal3-Jul-13 19:40 
GeneralRe: Login process Always false..cannot find the error Pin
mali_angel3-Jul-13 19:51
mali_angel3-Jul-13 19:51 
GeneralRe: Login process Always false..cannot find the error Pin
Shubhashish_Mandal3-Jul-13 19:54
professionalShubhashish_Mandal3-Jul-13 19:54 
QuestionactionPerformed in another class Pin
chdboy1-Jul-13 19:27
chdboy1-Jul-13 19:27 
How can I use another class actionPerformed in another main class?
I want to use this class actionperformed

Java
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.awt.Container;
import javax.swing.JOptionPane;
import java.awt.Frame;
import java.awt.event.*;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

public class SpringSample extends Frame implements ActionListener

{
		 JLabel F_namelbl = new JLabel("Username: ");
	    JLabel L_namelbl = new JLabel("Password: ");
	    JTextField tf_Fname = new JTextField(15);
	    JPasswordField tf_Lname = new JPasswordField(15);
	    JLabel Lbl_HW = new JLabel("< Login Area >");
	    JButton Btn = new JButton("Login");
	    JButton btn_cancel = new JButton("Cancel");
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	SpringSample()
	{
		
	    
		 JFrame frame = new JFrame("Login Area!");		 
		    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		    Container contentPane = frame.getContentPane();
		    JPanel p = new JPanel(new SpringLayout());
		    SpringLayout layout = (new SpringLayout());
		    contentPane.setLayout(layout);		   
		    JPanel p1=new JPanel();    
		   
		     
		    //--------------------------------------------------------------------------------------------------------------------
		    
		    //---------------------------------------------------------------------------------------------------------------------
		    /*Adding Components to the ContentPane */
		    frame.add(p1);
		    contentPane.add(F_namelbl);
		    contentPane.add(L_namelbl);
		    contentPane.add(tf_Fname);
		    contentPane.add(tf_Lname);
		    contentPane.add(Lbl_HW);
		    contentPane.add(Btn);
		    contentPane.add(btn_cancel);
		    	    
		      //--------------------------------------------------------------------------------------------------------------------
		    /*Lay out Components according to the position and coordinates on the SpringLayout*/
		    
		    layout.putConstraint(SpringLayout.WEST, Lbl_HW, 140, SpringLayout.WEST, contentPane);
		    layout.putConstraint(SpringLayout.NORTH, Lbl_HW, 0, SpringLayout.NORTH, contentPane);    
		    layout.putConstraint(SpringLayout.WEST, Lbl_HW, 140, SpringLayout.WEST, contentPane);
		    layout.putConstraint(SpringLayout.NORTH, Lbl_HW, 0, SpringLayout.NORTH, contentPane);
		    layout.putConstraint(SpringLayout.WEST, F_namelbl, 30, SpringLayout.WEST, contentPane);
		    layout.putConstraint(SpringLayout.NORTH, F_namelbl, 25, SpringLayout.NORTH, contentPane);
		    layout.putConstraint(SpringLayout.WEST, L_namelbl, 30, SpringLayout.WEST, contentPane);
		    layout.putConstraint(SpringLayout.NORTH, L_namelbl, 50, SpringLayout.NORTH, contentPane);
		    layout.putConstraint(SpringLayout.NORTH, tf_Fname, 25, SpringLayout.NORTH, contentPane);
		    layout.putConstraint(SpringLayout.WEST, tf_Fname, 15, SpringLayout.EAST, F_namelbl);
		    layout.putConstraint(SpringLayout.NORTH, tf_Lname, 50, SpringLayout.NORTH, contentPane);
		    layout.putConstraint(SpringLayout.WEST, tf_Lname, 15, SpringLayout.EAST, F_namelbl);
		    layout.putConstraint(SpringLayout.NORTH, Btn, 80, SpringLayout.NORTH, contentPane);
		    layout.putConstraint(SpringLayout.WEST, Btn, 110, SpringLayout.WEST, contentPane);
		    layout.putConstraint(SpringLayout.NORTH, btn_cancel, 80, SpringLayout.NORTH, p1);
		    layout.putConstraint(SpringLayout.WEST, btn_cancel, 200, SpringLayout.WEST, p1);	    
		    
		    //---------------------------------------------------------------------------------------------------------------------
		    /*Adding Action Listener/Action*/
		    btn_cancel.addActionListener(this);
		    Btn.addActionListener(this);
		    
		    //------------------------------------------------------------------------------------------------------------------------
		    /*Setting up JFrame*/
		    
		    frame.pack();
		    frame.setSize(350, 200);
		    frame.setLocationRelativeTo(null); //to appear frame in the center of the window screen
		    //setLocation(700,280);
		    frame.setVisible(true);	
	}
  public static void main(String args[]) 
  {	 
	  
    new SpringSample();    
   Connectionstring();  
  
    
    try {						 
		insertRecordIntoDbUserTable();
		selectfromdb();
	} 
	catch (SQLException e)
	{

		System.out.println(e.getMessage());

	}  
	  
  }
  //connection string method
  static Connection Connectionstring()
 	{		
 		Connection con = null;
 		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
 		String conUrl = "jdbc:sqlserver://localhost:1433; databaseName=paytest; user=PC; password=; integratedSecurity=true;";
 		
 		try 
 		{
 				 con = DriverManager.getConnection(conUrl);
 				 JOptionPane.showMessageDialog(null,"Connection is open!","Connection",JOptionPane.WARNING_MESSAGE);
 				 
 				 }
 		catch (SQLException e)
 		{
 			
 			e.printStackTrace();
 		}		
 		return con;
 		
 	}
  
  private static void insertRecordIntoDbUserTable() throws SQLException
	{
		Connection con = null;
		Statement statement = null;
		String insertTableSQL = "INSERT INTO LoginDetails" + "(Username, Password) " + "VALUES" + "('user1','user1')";
		try 
		{
			con = Connectionstring();
			statement = con.createStatement(); 
			System.out.println(insertTableSQL);			
			statement.executeUpdate(insertTableSQL);			
			
			JOptionPane.showMessageDialog(null,"Your Data has been Inserted","Data Inserted",JOptionPane.WARNING_MESSAGE);
		} 
		catch (SQLException e)
		{

			System.out.println(e.getMessage()); 
		} 
		finally 
		{

			if (statement != null)
			{
				statement.close();
				
				JOptionPane.showMessageDialog(null,"Statement is closed","Statement",JOptionPane.WARNING_MESSAGE);
			}

			if (con != null)
			{
				con.close();
				
				JOptionPane.showMessageDialog(null,"Connection is closed!","Connection",JOptionPane.WARNING_MESSAGE);
			}

		}
		
		
	}
 
  private static void selectfromdb() throws SQLException
	{		
	    Statement stmt = Connectionstring().createStatement();
		ResultSet rs = stmt.executeQuery("SELECT Username,Password FROM LoginDetails");
		while (rs.next())
		{
			  String lastName = rs.getString("Username");
			  String Pass = rs.getString("Password");
			  System.out.println(lastName + "" + Pass + "\n");
			 
			}		
	} 

 public void actionPerformed(ActionEvent e) 
{
	 
	if(e.getSource() == btn_cancel)
	{
		JOptionPane.showMessageDialog(null,"You have clicked on Cancel","button cancel",JOptionPane.WARNING_MESSAGE);
	}
	else if(e.getSource() == Btn)
	{
		//SpringSample sp = new SpringSample();
		//DBConnectionstring db = new DBConnectionstring();
		JOptionPane.showMessageDialog(null,"You have clicked login","button login",JOptionPane.WARNING_MESSAGE);		
		
	}
	
	

}
 
 //NEW CONNECTION STRING(CLASS) FOR JDBC CONNECTION I HOPE THIS WORKS
 
 
 
 
 
}

I want to use in this class


Java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
public abstract class ConnectionDB 
{	
	
	/**
	 * @param args
	 */
	public static void main(String[] args)
	{	
		SpringSample sp = new SpringSample();
		
		try {						 
			insertRecordIntoDbUserTable();
			selectfromdb();
		} 
		catch (SQLException e)
		{ 
			System.out.println(e.getMessage()); 
		}
}		
	private static void insertRecordIntoDbUserTable() throws SQLException
	{
		Connection con = null;
		Statement statement = null;
		String insertTableSQL = "INSERT INTO LoginDetails" + "(Username, Password) " + "VALUES" + "('null2','tf_Lname')";
		try 
		{
			con = DBConnectionstring();
			statement = con.createStatement(); 
			System.out.println(insertTableSQL);			
			statement.executeUpdate(insertTableSQL);			
			
			JOptionPane.showMessageDialog(null,"Your Data has been Inserted","Data Inserted",JOptionPane.WARNING_MESSAGE);
		} 
		catch (SQLException e)
		{
 
			System.out.println(e.getMessage()); 
		} 
		finally 
		{ 
			if (statement != null)
			{
				statement.close();				
				JOptionPane.showMessageDialog(null,"Statement is closed","Statement",JOptionPane.WARNING_MESSAGE);
			}
 
			if (con != null)
			{
				con.close();				
				JOptionPane.showMessageDialog(null,"Connection is closed!","Connection",JOptionPane.WARNING_MESSAGE);
			} 
		}		
	}	
	private static void selectfromdb() throws SQLException
	{		
	    Statement stmt = DBConnectionstring().createStatement();
		ResultSet rs = stmt.executeQuery("SELECT Username,Password FROM LoginDetails");
		while (rs.next())
		{
			  String lastName = rs.getString("Username");
			  String Pass = rs.getString("Password");
			  System.out.println(lastName + "" + Pass + "\n");			 
			}		
	}	
	 static Connection DBConnectionstring()
	{		
		Connection con = null;
		String conUrl = "jdbc:sqlserver://localhost:1433; databaseName=paytest; user=PC; password=; integratedSecurity=true;";		
		try 
		{
				 con = DriverManager.getConnection(conUrl);				
				 JOptionPane.showMessageDialog(null,"Connection is open!","Connection",JOptionPane.WARNING_MESSAGE);				 
				 }
		catch (SQLException e)
		{			
			e.printStackTrace();
		}		
		return con;		
	}
	 
	 
	 
	 
	}



How can I do that?
SuggestionRe: actionPerformed in another class Pin
Richard MacCutchan1-Jul-13 20:46
mveRichard MacCutchan1-Jul-13 20:46 
AnswerRe: actionPerformed in another class Pin
Shubhashish_Mandal3-Jul-13 19:48
professionalShubhashish_Mandal3-Jul-13 19:48 
Questionwhy java in linux has outstanding performance even jvm slow it down? Pin
crunchor28-Jun-13 17:55
crunchor28-Jun-13 17:55 
AnswerRe: why java in linux has outstanding performance even jvm slow it down? Pin
Richard MacCutchan28-Jun-13 23:19
mveRichard MacCutchan28-Jun-13 23:19 
GeneralRe: why java in linux has outstanding performance even jvm slow it down? Pin
crunchor28-Jun-13 23:22
crunchor28-Jun-13 23:22 
AnswerRe: why java in linux has outstanding performance even jvm slow it down? Pin
NotPolitcallyCorrect29-Jun-13 0:51
NotPolitcallyCorrect29-Jun-13 0:51 
QuestionMessage Closed Pin
27-Jun-13 17:11
crunchor27-Jun-13 17:11 
AnswerRe: official "forum" in oracle really screw up Pin
Richard MacCutchan27-Jun-13 21:23
mveRichard MacCutchan27-Jun-13 21:23 
GeneralRe: official "forum" in oracle really screw up Pin
crunchor27-Jun-13 21:40
crunchor27-Jun-13 21:40 
GeneralRe: official "forum" in oracle really screw up Pin
Richard MacCutchan27-Jun-13 22:33
mveRichard MacCutchan27-Jun-13 22:33 
GeneralRe: official "forum" in oracle really screw up Pin
Pete O'Hanlon27-Jun-13 22:59
mvePete O'Hanlon27-Jun-13 22:59 
GeneralRe: official "forum" in oracle really screw up Pin
Richard MacCutchan27-Jun-13 23:40
mveRichard MacCutchan27-Jun-13 23:40 
GeneralRe: official "forum" in oracle really screw up Pin
crunchor27-Jun-13 23:00
crunchor27-Jun-13 23:00 
AnswerRe: official "forum" in oracle really screw up Pin
jschell28-Jun-13 13:48
jschell28-Jun-13 13:48 
Questionjava media player with Java Media Frmework Pin
Md Shariful Islam Saful26-Jun-13 7:48
Md Shariful Islam Saful26-Jun-13 7:48 
AnswerRe: java media player with Java Media Frmework Pin
dusty_dex26-Jun-13 9:27
dusty_dex26-Jun-13 9:27 
GeneralRe: java media player with Java Media Frmework Pin
Md Shariful Islam Saful26-Jun-13 10:00
Md Shariful Islam Saful26-Jun-13 10:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.