Thread: SQL Connection Via Java

Results 1 to 2 of 2
  1. #1 SQL Connection Via Java 
    Registered Member
    CTucker's Avatar
    Join Date
    Oct 2008
    Posts
    2,422
    Thanks given
    263
    Thanks received
    281
    Rep Power
    343
    Hello, I am just starting to use Java to connect to sql and i have a question

    Where can i find codes showing how to get the java program to connect to the sql server and "alter / add" stuff to the table/database

    Like for instance, in php you would use this

    Code:
    <?php
    $dbhost = "localhost";
    $dbname = "helloworld";
    $dbuser = "root";
    $dbpass = "";
    
    //Connect to database
    
    mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    Now to add a User to the database it would use this code

    Code:
    $query = "INSERT INTO users (CurrentEnergy, MaxEnergy, CurrentStamina, MaxStamina, Experience, Level, name, email, username, password)
    VALUES('10', '10', '3', '3', '0', '1', '$name', '$email', '$username', '$password')";
    mysql_query($query) or die(mysql_error());
    mysql_close();
    I am simply wondering how you would go about doing this in java, the php codes above are based from a php game i was in the process of creating.

    Thanks for the help, and i don't want links to tutorials how to configure it for runescape private server's because i am using my own framework, that will be released when i feel like it is stable enough.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Mister Maggot's Avatar
    Join Date
    Dec 2008
    Posts
    7,227
    Thanks given
    3,283
    Thanks received
    2,875
    Rep Power
    5000
    Using JBDC, make a new connection, then execute a query through that connection...
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •