Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default database conetivity

    it is my fisrt java program that have one error plz correct this




    import java.sql.*;
    import java.io.*;
    public class database
    {
    public static void main(String arg[]}
    {

    String url;
    String userID = "jim";
    String password = "keogh";
    Connection Db;
    Statement DataRequest;

    ResultSet Results;
    try
    {
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
    db = DriverManager.getConnection("jdbc:odbc:db1","","") ;
    }
    catch(Exception e)
    {
    }

    try
    {
    String query = "SELECT * FROM table1";
    //DataRequest = Database.createStatement();
    DataRequest = Db.createStatement();
    Results = DataRequest.executeQuery (query);

    }
    catch(Exception ae)
    {
    System.out.println(" exception of request");
    }

    /*
    String FirstName;
    String LastName;
    String printrow;
    boolean Records = Results.next();
    if (!Records )
    {
    System.out.println( "No data returned");
    return;
    }
    else
    {
    do
    {
    FirstName = Results.getString (name) ;
    LastName = Results.getString (password) ;
    printrow = " " + LastName;
    System.out.println(printrow);
    }
    while ( Results.next() );
    }
    */

    DataRequest.close();
    Db.close();
    }

    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by rehan4uusmalik View Post
    it is my fisrt java program that have one error plz correct this
    What do you want us to do? Guess what the error is?

    kind regards,

    Jos

  3. #3
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default

    find the error and correct it

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

    Default

    @JosAH - this is a test. If you can pass this one, the OP will award you a prize.
    If you fail, you'll have to go back to the beginning.
    You have 30 seconds. On your mark, get set. GOOOOOOOOOOOO!

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Norm View Post
    @JosAH - this is a test. If you can pass this one, the OP will award you a prize.
    If you fail, you'll have to go back to the beginning.
    You have 30 seconds. On your mark, get set. GOOOOOOOOOOOO!
    Oh dear, and now the OP is even giving me orders "find the error and correct it". I can't even read that code, I don't stand a chance ... I wonder how much he is paying ...

    kind regards,

    Jos ;-)

  6. #6
    ujjal.ruet is offline Member
    Join Date
    Apr 2010
    Posts
    9
    Rep Power
    0

    Default Here is solution.You please changr url,userID,password,class.forName(" "),then run it

    /////

    import java.sql.*;
    import java.io.*;

    public class data{

    public static void main(String arg[])
    {

    String url = "jdbc:mysql://localhost/cse300";
    String userID = "root";
    String password = "123456";
    Connection db=null;
    Statement DataRequest=null;

    ResultSet Results=null;
    try
    {
    Class.forName("com.mysql.jdbc.Driver");
    db = DriverManager.getConnection(url,userID,password) ;
    }
    catch(Exception e)
    {
    }

    try
    {

    String query = "SELECT * FROM articlee";
    //DataRequest = Database.createStatement();
    DataRequest = db.createStatement();
    Results = DataRequest.executeQuery (query);

    }
    catch(Exception ae)
    {
    System.out.println(" exception of request");
    }

    /*
    String FirstName;
    String LastName;
    String printrow;
    boolean Records = Results.next();
    if (!Records )
    {
    System.out.println( "No data returned");
    return;
    }
    else
    {
    do
    {
    FirstName = Results.getString (name) ;
    LastName = Results.getString (password) ;
    printrow = " " + LastName;
    System.out.println(printrow);
    }
    while ( Results.next() );
    }
    */
    String s;
    try{
    if(Results.next()){

    s=Results.getString(1);
    System.out.println(s);
    }
    }
    catch (SQLException ex) {
    ex.printStackTrace();
    // System.out.println(query);

    }
    /*DataRequest.close();
    db.close();
    */}

    }

Similar Threads

  1. Use the database from other pc
    By AbdulAziz Bader in forum JDBC
    Replies: 3
    Last Post: 06-07-2010, 01:59 PM
  2. xml to database from xml rpc
    By kievari in forum JDBC
    Replies: 1
    Last Post: 12-11-2009, 12:14 AM
  3. help with database
    By fahien_akim in forum NetBeans
    Replies: 0
    Last Post: 03-07-2009, 01:44 PM
  4. Replies: 2
    Last Post: 02-11-2009, 04:43 AM
  5. Database in a PDA
    By percivalwcy in forum JDBC
    Replies: 2
    Last Post: 08-08-2007, 03:10 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
  •