Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Norm

Thread: my application is not connectioning to mysql database

  1. #1
    mDennis10 is offline Member
    Join Date
    Jul 2011
    Posts
    76
    Rep Power
    0

    Default my application is not connectioning to mysql database

    i'm writing a program that needs to connect to a mysql database to retrieve username and password amoung other data, however when i compile and click log in its telling me can't connect to database. here is the code:
    Java Code:
    
    String username = "";
    String passWorD = "";
    String Year = " ";
    	try 
    	{
    		Connection con = DriverManager.getConnection ("jdbc:mysql://localhost/ncu students","mario","computer");
    		Statement state = null;
    		state = con.createStatement ();
    		ResultSet result = state.executeQuery("SELECT user name, password,year FROM student info");
    						
    		while (result.next())
    			{
    				username = result.getString("user name");
    				passWorD = result.getString("password");
    				Year = result.getString("year");
    			}
    						
    			con.close ();
    	 }
    	catch (Exception r)
    	{
    		System.out.println ("could not connect");
    	}
    	JOptionPane.showMessageDialog(null,"user Name: "+username+" password: "+passWorD + " year:"+Year);

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    Add a call to the printStackTrace method to your catch block to show what the error is. Your silly error message is not telling you what is wrong.

    BTW Always have a call to the printStackTrace method in catch blocks.
    Last edited by Norm; 08-20-2011 at 12:16 AM.
    Joel likes this.

  3. #3
    mDennis10 is offline Member
    Join Date
    Jul 2011
    Posts
    76
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Add a call to the printStackTrace method to your catch block to show what the error is. Your silly error message is telling you what is wrong.

    BTW Always have a call to the printStackTrace method in catch blocks.
    did that then the error meassage i got is
    Java Code:
    java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    	at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:479)
    	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1435)
    	at NcuApp$EventHandler.actionPerformed(NcuApp.java:188)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$000(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    don't k now what it means

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,247
    Rep Power
    19

    Default

    I don't do JDBC, but this doesn't look right to me.
    Java Code:
    SELECT user name, password,year FROM student info
    Can a table name include a space? I think not.

    db

  5. #5
    Paul_White is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Try this

    You can have spaces in names but you will need to put the name in ' ' otherwise the name will be seen as two separate fields.

    I would chabe the query to this:

    "SELECT user name, password,year FROM 'student info'");

  6. #6
    mDennis10 is offline Member
    Join Date
    Jul 2011
    Posts
    76
    Rep Power
    0

    Default

    Quote Originally Posted by DarrylBurke View Post
    I don't do JDBC, but this doesn't look right to me.
    Java Code:
    SELECT user name, password,year FROM student info
    Can a table name include a space? I think not.

    db
    well thats the problem the sql statement was incorrect i fixed it and now it's ok

  7. #7
    Joel's Avatar
    Joel is offline Member
    Join Date
    May 2011
    Location
    Placerville, CA
    Posts
    86
    Rep Power
    0

    Default

    ALL HAIL mrDarrylBurke! Solving problems and such. BTW @DarrylBurke, what database do you use in your Java programming? Just curious...
    ~MSP430 Lover~

  8. #8
    mDennis10 is offline Member
    Join Date
    Jul 2011
    Posts
    76
    Rep Power
    0

    Default

    Quote Originally Posted by Joel View Post
    ALL HAIL mrDarrylBurke! Solving problems and such. BTW @DarrylBurke, what database do you use in your Java programming? Just curious...
    it's mysql database

Similar Threads

  1. Replies: 9
    Last Post: 01-17-2012, 08:31 AM
  2. Replies: 2
    Last Post: 05-09-2011, 06:55 PM
  3. How to connect database mysql via Lan
    By ahmed30 in forum JDBC
    Replies: 3
    Last Post: 01-17-2011, 06:36 AM
  4. Replies: 3
    Last Post: 10-28-2010, 02:42 PM
  5. Replies: 2
    Last Post: 02-11-2009, 04:43 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
  •