Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How To Set Up Database In Java Eclipse

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default How To Set Up Database In Java Eclipse

    i already have xammp set up on localhost. and
    i also added a "mysql-connector-java-5.1.22-bin" file to m exlipse under "JRE SYSTEM LIBRARY"

    information on xammp:
    user name: "root"
    password: ""
    database: "a_upload"
    table: "user"

    in eclipse iam just testing my connection. but i get a error:
    SQLException: Unknown database '/a_upload'
    SQLException: 1049


    how i now what the error mean but i dont now why it give me the error.


    import java.sql.*;
     
    public class database01
    {
    	public static void main(String[]args)
    	{
    		Connection connect = null;
     
    		try{
    			Class.forName("com.mysql.jdbc.Driver");
    			connect = DriverManager.getConnection("jdbc:mydql://localhost//a_upload","root","");
    			Statement sqlState = connect.createStatement();
     
    			String selectStuff = "Select firstname from user";
    			ResultSet rows = sqlState.executeQuery(selectStuff);
    			while(rows.next())
    			{
    				System.out.println(rows.getString("firstname"));
    			}
    		}
    		catch(SQLException e){
    			System.out.println("SQLException: "+e.getMessage());
    			System.out.println("SQLException: "+e.getErrorCode());
    		}
    		catch(ClassNotFoundException e){
    			e.printStackTrace();
     
    		}
    	}
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How To Set Up Database In Java Eclipse

    Thread moved from what's wrong with my code

    dbc:mydql
    Check spelling on the URL. There error however indicates the database does not exist. Can you log in through a terminal as root into that particular database?

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: How To Set Up Database In Java Eclipse

    terminal as in mac? but iam on windows so i use cmd?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How To Set Up Database In Java Eclipse

    Quote Originally Posted by hwoarang69 View Post
    terminal as in mac? but iam on windows so i use cmd?
    MySQL comes with the mysql tool which you can use to login to a database using the command line. Try connecting to your database this way. See the docs of Mysql for how to use this tool (for instance 'mysql.exe --help')

Similar Threads

  1. Database Connect Error on Eclipse ( JAVAEE/Glassfish)
    By thisbeme in forum JDBC & Databases
    Replies: 0
    Last Post: March 6th, 2012, 07:27 AM
  2. set database unicode
    By serdar in forum Java Theory & Questions
    Replies: 0
    Last Post: July 21st, 2011, 04:42 AM
  3. Website to study Struts framework
    By kirman in forum Java IDEs
    Replies: 2
    Last Post: October 17th, 2008, 07:26 AM