how to connect java programme to a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahana
    New Member
    • Oct 2007
    • 12

    #1

    how to connect java programme to a database

    My java programme is unable to connect to the database..

    my code is this

    [code=java]
    import java.sql.*;

    public class Stmt
    {
    public static void main(String args[])throws Exception
    {

    try{
    Class.forName(" oracle.jdbc.dri ver.OracleDrive r");
    Connection con=DriverManag er.getConnectio n("jdbc:oracle: thin@localhost: 1521:xe","scott ","tiger");
    Statement stmt=con.create Statement();
    String vsql="create table testtable(cone number,ctwo number)";
    stmt.executeUpd ate(vsql);
    System.out.prin tln("...Success ....");
    con.close();
    }
    catch(ClassNotF oundException e)
    {
    System.out.prin tln(e);
    System.out.prin tln("hello");
    }

    }
    }
    [/code]

    My java programme is compiling but not running I am getting error as Exception in thread "main" java.sql.SQL exception,conne ction refused.


    Please give answer to my question ,i am struck here and unable to go further
    Last edited by JosAH; Oct 19 '07, 08:12 AM. Reason: added [code] ... [/code] tags
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by rahana
    My java programme is compiling but not running I am getting error as Exception in thread "main" java.sql.SQL exception,conne ction refused.


    Please give answer to my question ,i am struck here and unable to go further
    There are a few possible causes:

    1) wrong port number
    2) wrong user name and/or password
    3) no database server running
    4) error in your url for the connection request
    5) database server too busy already
    6) firewall problems

    You have to check them all and google a bit.

    kind regards,

    Jos

    Comment

    • rahana
      New Member
      • Oct 2007
      • 12

      #3
      Originally posted by JosAH
      There are a few possible causes:

      1) wrong port number
      2) wrong user name and/or password
      3) no database server running
      4) error in your url for the connection request
      5) database server too busy already
      6) firewall problems

      You have to check them all and google a bit.

      kind regards,

      Jos
      how can i know the port number,user name,password and url

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by rahana
        how can i know the port number,user name,password and url
        What about reading your database vendor's manual?

        kind regards,

        Jos

        Comment

        Working...