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 9 of 9

Thread: Fundamental steps to create a database program in java

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Fundamental steps to create a database program in java

    Hi,
    I am new to java programming.And i want to create a database named vehicle info. I need to program it in Android eclipse .
    The requirements are 1.I should do program code to create a database named vehicle info.Then i should get the details from the MySQl databse, store new informations etc...
    Which all software i should install in my system
    I have Android SDK , i have to do in eclipse.
    i dont have any other software installed in my system related to this as i dont know what all thigs i need ..and i dont know the procedures to setup.
    can anyone help me to create databse.
    then do the connection
    and veiw ,update ,delete operations..


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Saint-Petersburg, Russia
    Posts
    33
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: Fundamental steps to create a database program in java

    Which all software i should install in my system
    I have Android SDK , i have to do in eclipse.
    If you google for "Android SDK" you'll find it at once, and it contains Eclipse already setup, so that installing the whole thing is as easy as lying.

    can anyone help me to create databse.
    then do the connection
    and veiw ,update ,delete operations..
    You'd better compose yourself and write it yourself if you need it. The program is not complicated (you can use SQLite in Android) and with Android tutorials (at the same site) it will not be hard. However it will really take some time so I doubt anyone is interested to do this stuff for you (at least without good payment).

    Android SDK | Android Developers

    Getting Started | Android Developers

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fundamental steps to create a database program in java

    I have already installed eclipse.But for my application i need to create a database called vehicleinfo .It is with MySQL . I installed mysql and the mysql driver also.
    Now i just want to know how can i create a database with all these utilites and to connect my eclipse with the created database.
    Thanks for help!!!!!!

  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: Fundamental steps to create a database program in java

    Your request involves a whole slew of things, all of which are in depth - not necessarily trivial - topics. My advice:
    a) Read Trail: JDBC(TM) Database Access (The Java™ Tutorials)
    b) consult MySQL :: The world's most popular open source database for MySQL related issues
    c) If you need an embedded database, use a more appropriate database to meet the task (my understanding is that at this time MySQL is not embedded)
    d) If you wish database info to be shared, you must set up an (or use a pre-set up) instance on a central server that can be accessed remotely by your app

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fundamental steps to create a database program in java

    Hi, Thanks for your answer.
    Now i created a database .After creating MySQL database from MySQL I move to eclipse.I choose Data development perspective . I choose new Database connections in data source explorer.Then next choose MySQL as database next give database name which i created next select jdbc driver which is locsted in MySQL directory , the jar file ...next give name ,user and password details.. then i tried for test connection and i am getting error as
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Unknown database 'database'
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:41 1)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:1054)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:4190)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:4122)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:927)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggab leAuthentication(MysqlIO.java:1709)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:12 52)
    What might be the issue with my connection or with something else ?
    Thanks !!!!!

  6. #6
    Member
    Join Date
    Oct 2013
    Location
    Saint-Petersburg, Russia
    Posts
    33
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: Fundamental steps to create a database program in java

    Quote Originally Posted by Sharonswaroop View Post
    What might be the issue with my connection or with something else ?
    Looks like you specified wrong database name in your connection url or properties.

  7. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fundamental steps to create a database program in java

    i created database in mysql , the name is vehicleinfo .So i just give that name in the eclipse .Also i provided the path for jdbc driver .
    But the ping is got failed. Is there any suggestions ?

    i created a database called vehicleinfo in MySQL and the table name details

    i can paste my program code below in my eclipse .

    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.SQLException;
    public class DisplayAuthors
    {
    //database URL
    static final String DATABASE_URL= "jdbc:mysql://localhost/vehiclinfo";

    //launch application
    public static void main(String args[])
    {
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    try
    {
    connection = DriverManager.getConnection(DATABASE_URL,"root","r oot");
    statement = connection.createStatement();
    resultSet = statement.executeQuery("SELECT ID,LicenseNumber,Model,Yearofreg FROM details");
    ResultSetMetaData metaData = resultSet.getMetaData();
    int numberOfColumns = metaData.getColumnCount();
    System.out.println("details Table of vehicleinfo Database:\n");
    for (int i = 1;i <= numberOfColumns; i++ )
    System.out.printf("%-8s\t",metaData.getColumnName(i));
    System.out.println();
    while (resultSet.next())
    {
    for(int i = 1;i<= numberOfColumns; i++)
    System.out.printf("%8s\t",resultSet.getObject(i));
    System.out.println();
    }
    }
    catch(SQLException sqlException)
    {
    sqlException.printStackTrace();
    }
    finally
    {
    try
    {
    resultSet.close();
    statement.close();
    connection.close();
    }
    catch (Exception exception)
    {
    exception.printStackTrace();
    }
    }

    }
    }


    Then i create a new database connection drom Database development perspective ....as below :
    Data connections --->new -->select MySQL-->name vehicleinfo --> set path for jdbc driver --> give username and password of databse ---> Test connection
    Then i got ping failed error

    .

    Please help me to resolve the issue

  8. #8
    Junior Member
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fundamental steps to create a database program in java

    Hi...
    Now it is ping message came.
    But when i run as java application the error is coming as driver not found.
    Can anybody suggest how to define program's classpath,
    Where we should define program's class path like as below
    java -classpath
    .;C:\Program Files (x86)\MySQL\Connector J 5.1.26\mysql-connector-java-5.1.26-bin.jar classname ?

    thanks !!!!!

  9. #9
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Fundamental steps to create a database program in java

    Here are the results of searches you could have done yourself. Don't be helpless:

    Oracle: How to set the classpath.

    Javarevisited: Setting the classpath.

Similar Threads

  1. Java Fundamental
    By jmsrajeev in forum Java Theory & Questions
    Replies: 13
    Last Post: June 3rd, 2013, 09:31 PM
  2. How to connect or create database by using mysql to java
    By hafiz013 in forum Java Theory & Questions
    Replies: 4
    Last Post: January 3rd, 2013, 04:28 AM
  3. Replies: 1
    Last Post: December 30th, 2011, 03:29 AM
  4. Display Execution Steps - Java Program
    By Max Avion in forum Java Theory & Questions
    Replies: 7
    Last Post: September 14th, 2011, 07:31 PM