Results 1 to 4 of 4
  1. #1
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default Can't connect my connection string in MS SQL sERVER 2005

    hey guys im using sql server 2005 and my error is the connection string (com.microsoft.sqlserver.jdbc.SQLServerDriver) itself...

    Java Code:
    package webportalcms;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.MouseAdapter;
    import org.eclipse.swt.events.MouseEvent;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.graphics.Image;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.MessageBox;
    import org.eclipse.swt.widgets.Monitor;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Text;
    
    public class mainPage {
    	final static Display display= new Display();
    	final static Shell shell = new Shell(display);
    	static Connection connect = null; static Statement stmt = null;
    	static ResultSet rs = null; //static configuration config = new configuration();
    	public static void main(String[] args) {
    		final Shell login = new Shell(shell);//,SWT.NO_TRIM
    		login.setSize(350,200);
    		Monitor primary = display.getPrimaryMonitor();
    		Rectangle bounds = primary.getBounds();
    		Rectangle rect = login.getBounds();
    		int x = bounds.x+(bounds.width-rect.width)/2;
    		int y = bounds.x+(bounds.width-rect.width)/2;
    		login.setLocation(x,y);
    		login.open();
    		
    		Composite comp = new Composite(login,SWT.BORDER);
    		comp.setBounds(0,0,350,80);
    		comp.setBackground(new Color(display,255,255,255));
    		
    		Image img = new Image(display,"bin/icon/loginlogo.jpg");
    		Label logo=new Label(comp,SWT.NONE);
    		logo.setImage(img);
    		logo.setBounds(10,1,100,65);
    		
    		Label lblWelcome = new Label(comp,SWT.NONE|SWT.WRAP|SWT.CENTER);
    		lblWelcome.setText("Webportal With Content Management System");;
    		lblWelcome.setBounds(120,20,200,50);
    		lblWelcome.setBackground(new Color(display,255,255,255));
    		final Text txtUsername = new Text(login,SWT.BORDER);
    			txtUsername.setBounds(100,100,150,23);
    			txtUsername.setFocus();
    			txtUsername.addMouseListener(new MouseAdapter(){
    				public void mouseDown(MouseEvent e){
    					txtUsername.selectAll();
    				}
    			});
    			
    		final Text txtPassword = new Text(login,SWT.BORDER|SWT.PASSWORD);
    			txtPassword.setBounds(100, 130, 150, 23);
    			txtPassword.addMouseListener(new MouseAdapter(){
    				public void mouseDown(MouseEvent e){
    					txtPassword.selectAll();		
    				}
    			});
    			
    		Label lblUsername = new Label(login,SWT.NONE);
    			lblUsername.setText("Username: ");
    			lblUsername.setBounds(40,105,50,25);
    		Label lblPassword = new Label(login,SWT.NONE);
    			lblPassword.setText("Password:");
    			lblPassword.setBounds(40, 135, 50, 25);
    		Button btnLogin = new Button(login,SWT.PUSH);
    			btnLogin.setText("Log In");
    			btnLogin.setBounds(260,100,50,25);
    			btnLogin.addSelectionListener(new SelectionAdapter(){
    				public void widgetSelected(SelectionEvent e){
    					[B]try
    					{ 
    									
    						Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    						String URL = "jdbc:sqlserver://pal;databaseName=CLMS";
    						connect= DriverManager.getConnection(URL,"admin","");
    						String query = "SELECT * FROM tbladmin";
    						stmt = connect.createStatement();
    						rs = stmt.executeQuery(query);
    						while (rs.next())
    						{
    							if((txtUsername.getText()).equals(rs.getString("useradmin"))&&(txtPassword.getText()).equals(rs.getString("passwrd"))){
    								login.setVisible(false);
    								new STI_Taft(display,shell);
    							}[/B]
    							else{
    								MessageBox box = new MessageBox(login,SWT.ICON_ERROR);
    								box.setMessage("Username and Password mismatch");
    								box.setText("Error");
    								box.open();
    							}
    						}
    					}
    					/*catch (ClassNotFoundException ex)
    					{System.out.println(ex.getMessage());}*/
    					catch (SQLException ex)
    					{System.out.println(ex.getMessage());}
    					catch (Exception ex)
    					{System.out.println(ex.getMessage());}
    					finally{
    					 if (rs != null) try { rs.close(); } catch(Exception e1) {}
    				     if (stmt != null) try { stmt.close(); } catch(Exception e1) {}
    				     if (connect != null) try { connect.close(); } catch(Exception e1) {}
    					}
    				}
    			});
    	
    		Button btnCancel = new Button(login,SWT.PUSH);
    			btnCancel.setText("Exit");
    			btnCancel.setBounds(260, 130, 50, 25);
    			btnCancel.addSelectionListener(new SelectionAdapter(){
    				public void widgetSelected(SelectionEvent e){
    					login.close();
    				}
    			});
    		while (!login.isDisposed()){
    			 if(!display.readAndDispatch()){
    				 display.sleep();
    			 }
    			 display.isDisposed(); 
    		 }
    	}
    }
    :cool:

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    286
    Rep Power
    11

    Default

    Whats the exact error message? Please use code tags while pasting codes.
    Swastik

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    878
    Rep Power
    11

    Default

    check whether driver class "com.microsoft.sqlserver.jdbc.SQLServerDriver" is available or not.
    Ramya:cool:

  4. #4
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    actually the exact error is the connection string itself. i already import the sqljdbc.jar in my project... any idea?

    this is the image link:

    error | Flickr - Photo Sharing!


    when i hit the Login button, the error connection string appeared..

    thank you in advance guys..
    :cool:

Similar Threads

  1. Replies: 7
    Last Post: 03-17-2012, 10:46 AM
  2. Replies: 4
    Last Post: 09-07-2010, 06:51 AM
  3. Replies: 3
    Last Post: 03-28-2010, 06:55 AM
  4. Connect to SQL server 2005
    By comp in forum JDBC
    Replies: 1
    Last Post: 03-25-2009, 11:25 PM
  5. SQL Server 2005 Jdbc connection
    By mgt83 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 07-27-2007, 04:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •