How to connect java in mysql....

how to connect java in mysql.... help me guys
am newbie...

http://www.mysql.com/products/connector/j/
download the JDBC driver and read the docs.
if you don't know JDBC, Google for "Sun JDBC tutorial" and study it.
don't ask for sample code. there's plenty out there.
%

Similar Messages

  • Can' t connect Java with MySQL

    My goal is to connect Java with MySQL. I found many solutions on Internet, but I always get the same mistake:
    SQLException: No suitable driver
    SQLState: 08001
    VendorError: 0MySQL works fine alone or with php.Only thing left me to think is that the installed versions are not compatible for this mysql-connector-java-5.0.4
    I don't believe that could be a reason.
    Installed versions are:
    Apache Tomcat 5.5.20 Server
    Apache HTTP Server 2.2.4
    PHP 5.2.0
    MySQL 5.2
    jre 1.5.0_11
    jdk1.5.0_11
    Apache Tomacat JK2 connector Version: 1.2.20 File Name: mod_jk-apache-2.2.3.so
    mysql-connector-java-5.0.4
    I also set connector in class path: C:\mysql-connector-java-5.0.4;C:\mysql-connector-java-5.0.4\mysql-connector-java-5.0.4-bin.jar;C:\mysql-connector-java-5.0.4\src\com\mysql\jdbc
    For installation I used manulas from:
    http://apacheguide.org/jsp.php
    http://doc.51windows.net/mysql/?url=/MySQL/ch23s03.html
    Here is also a test code in java:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
       public class Connect
           public static void main (String[] args)
               Connection conn = null;
               try {
        conn =
           DriverManager.getConnection("jdbc:mysql://localhost/first_test" +
                                       "user=monty&password=greatsqldb");
        // Do something with the Connection
    } catch (SQLException ex) {
        // handle any errors
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
       }i'm desperate, please help or tell me someone who'll know the answer.
    Thank You in advance

    hey buddy .. it seems yr code is wrong .. in getconnection () method u should also specify the port ,which u r not doing ...
    the default port for MySQL is 3306 ... see below i am giving you a sample code ... its working fine .. and dont forget to put the MySQL driver jar path in to classpath and also copy the jar into common/lib folder of your tomcat ....
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class MySQLConnectionTest {
         public static void main(String[] args) {
    new MySQLConnectionTest().connTest();
    public void connTest() {
              String tableName = "portfolio"; //change as per setting
              String hostName = "10.81.9.39"; // please change for the target database ip or hostname
              String dbPort = "3306"; //change if not using the default
              String dbName = "tradingsystem"; //change as per the given DB name
              String username = "root"; //change as per setting
              String password = "password"; //change as per setting
              System.out.println("before try");
              Double data=0.0;
         Double data1=0.0;
              try {
    Class.forName("org.gjt.mm.mysql.Driver");
                   System.out.println("before driver manager");
    Connection conn = DriverManager.getConnection("jdbc:mysql://"+hostName+":"+dbPort+"/"+dbName, username, password);
    String query1 = "select * from "+tableName+" where User_id='trader1' and Stock_Type='Equity'";
    System.out.println("quesry1="+query1);
    Statement stmt = conn.createStatement();
    ResultSet rs1 = stmt.executeQuery(query1);
    while(rs1.next())
         System.out.println("hiiiiii for rs1");
         System.out.println(rs1);
         Quantity=(Integer)rs1.getObject(5);
         MarketPrice=(Double) rs1.getObject(8);
         data=Quantity*MarketPrice;
         data1+=data;
         System.out.println("data1="+data1);
         i=0;
    rs1.close();
    stmt.close();
    conn.close();
    } catch (ClassNotFoundException e) {
    e.printStackTrace(System.err);
    } catch (SQLException e) {
    e.printStackTrace(System.err);
    i hope it will work for u...
    cheers,

  • How to connect Java and Microsoft SQL Server 2000

    hi,
    could anyone please teach me how to connect Java and SQL Sever 2000?? if possible could you guys provide me with an example??? i could hardly find any relevant resources about it...
    Thanks ~!

    thanks for the information...
    by the way hv any working module on it?? i'm new to
    both Java and Microsoft SQL Server... Thanks againFirst things first... you should read this:
    http://java.sun.com/docs/books/tutorial/jdbc/
    This is microsofts official JDBC Driver: http://www.microsoft.com/sql/downloads/jdbcregister.asp
    Install it and the documentation has some usage examples

  • How to connect Java into BarTender Label Printing Software

    Hi,
    I have one problem, my company have bartender label printing software 32 bit version, previously they use VB6 for controlling the dublicate printing of lable,but the software is gone. Now i want to do this in Java, but i don't know how to connect java into Bartender software.
    my company using old version, it accept only VB6. My Boss said can buy new Bartender Software but i don't know how to link and control dublicate printing. if anybody knows this connection between Bartender and Java please help me.
    if bartender New version support this features please send the link and example source code please help me.
    AnbuAathi

    Hi , i have the similar task ,where i need to connect my web portal application with the bartender software .I did a hugh R&D to integrate Java application with Bartender software but did not find any luck .So i request to provide the needed help to integrate my Java Application with Bartender software .
    Thanks in Advance
    Mohan

  • How to connect Java to oracle Database Express Edition?

    Anyone can help me?
    How to connect JAVA TO ORACLE DATABASE EXPRESS EDITION?

    I suggest you to read this article:
    http://wiki.oracle.com/page/JDBC
    Regards,
    Ricky

  • How to connect Java to crystal report

    How to connect java with crystal report ?
    Which are the API's for that

    In all this time you never considered searching?
    Cross post
    http://forum.java.sun.com/thread.jspa?threadID=791154

  • How to connect java with oracle

    can any body show me the code of how to connect java with oracle database.
    thank you

    To configure Oracle JDBC:
    1. Add Oracle JDBC JAR file classes12.zip or ojdbc14.zip to classpath.
    2. Load and register the JDBC driver.
    Class.forName("oracle.jdbc.driver.OracleDriver");
    3. Obtain a connection:
    String url="jdbc:oracle:thin:@<host>:1521:<database>
    Connection con = DriverManager.getConnection(url,
    "myLogin", "myPassword");
    4. Create a SQL statement.
    Statement stmt = con.createStatement();
    5. Obtain a result set.
    ResultSet rs = stmt.executeQuery(
    "SELECT ...");

  • How to connect java to MS Access

    How to connect java to MS Access using jdbc
    Can U write the complete code for it ? How to interact with the fields ?

    G O O G L E
    http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2691&lngWId=2
    http://blog.taragana.com/index.php/archive/how-to-access-ms-access-database-from-jdbc/

  • Cannot connect java to mysql server 2000

    I was unable to connect to the mysql server 2000 with the jcreator.
    The following exception was thrown:
    java.net.SocketException
    MESSAGE: java.net.ConnectException: Connection refused: connect
    STACKTRACE:
    java.net.SocketException: java.net.ConnectException: Connection refused: connect at com.mysql.jdbs.StandardSocketFactory.connect<StandardSocketFactory.java:156?
    at com.mysql.jdbc.MysqlIO.<init><MysqlIO.java:284>
    ** END NESTED EXCEPTION **
    and the code i used was :
    package com.stardeveloper.example;
    import java.sql.*;
    public class JCustomer {
    public static void main(String args[]) {
    Connection con = null;
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql:///Customer", "user", " ");
    if(!con.isClosed())
    System.out.println("Successfully connected to MySQL server...");
    } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
    } finally {
    try {
    if(con != null)
    con.close();
    } catch(SQLException e) {}
    I donot have any user and pwd for the MYsql server, it is local host connection and window authentication is used.

    eventhough it is local ,you may need to specify dns/localhost/ip with port number.
    otherwise you can use myODBC driver which is freely available in mysql website. you can connect to the database using Data source Name, just like using any other ODBC connectivity.

  • How to connect APEX with MYSQL via Apex's Database link

    How do i connect APEX with MYSQL via Apex's Database link? The OBE doesn't go into specific detail about how to link the two.
    can someone please elaborate on what these are and where i can find them in mysql:
    Database Link Name      
    Connect To Schema      
    Password      
    Remote Hostname or IP      
    Remote Host Port      
    SID or Service Name      
    I need to link to mysql database so I can set up a 3D pie chart in apex

    Hi jononioo
    A database link is a device for connecting between Oracle database instances only. Oracle does have a method for connecting to other database systems (Transparent Gateway) but this is restricted to other commercial databases and I don't believe there is a gateway for Mysql. (I could be wrong)
    I don't know Mysql but maybe there is some way to push data to the Oracle instance. Other than that, is there any reason why the data has to reside in the Mysql database?
    Regards
    Andre

  • How to connect java with C

    Plz help....
    How to Connect a Java With C ....

    using the JNI, Java Native Interface. there are tons of tutorials on the web about it, that will explain far better and more completely than a few posts on a forum

  • Unable to connect java to mysql

    I have installed mysql on my linux machine (i didnt modify any default configuration settings, just using the default settings). And in my lan, from another machine in windows from my java code i am trying to connect to mysql of linux, but donno why i get connection refused error. Can someone help me to figure what the steps i am missing or need to do?

    Thanks for your reply. I do not have any network managers. I have installed mysql on my linux machine and also started mysql. Now in remote machine i have downloaded mysql-connector-java-5.0.4-bin.jar file and using this jar file my java code is trying open a connection to mysql.
              try {
                   Class.forName("com.mysql.jdbc.Driver");
              }catch(Exception ce) {ce.printStackTrace();}
              try {
                   Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.20.160:3306/mysql","root","new_password");192.168.20.160 is the linux machine where mysql is running.
    But of no use, i get connection refused error. following is stacktrace
    SQLException: Communications link failure due to underlying exception:
    ** BEGIN NESTED EXCEPTION **
    java.net.SocketException
    MESSAGE: java.net.ConnectException: Connection refused: connect
    STACKTRACE:
    java.net.SocketException: java.net.ConnectException: Connection refused: connect
         at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
         at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
         at com.mysql.jdbc.Connection.createNewIO(Connection.java:2666)
         at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
         at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
         at java.sql.DriverManager.getConnection(DriverManager.java:525)
         at java.sql.DriverManager.getConnection(DriverManager.java:171)
         at TestDriver.main(TestDriver.java:11)
    ** END NESTED EXCEPTION **
    Last packet sent to the server was 63 ms ago.
    SQLState: 08S01
    VendorError: 0

  • How to connect JSP with MySql Database?

    HI All...
    I want to know or How to connect Mysql with JSP or JSF any other software is available? please help me.....

    I want to know or How to connect Mysql
    with JSP or JSF any other software isavailable?
    please help me.....First you need to find 25 m of a CatV cable and...The DB files need to be located on the ninth device of a SCSI Daisy Chain with the total SCSI cable length being over 150 m (and the devices (and cables) need to be mix of Differential and Non-Differential).
    Edit: And forget the terminator, who needs it?

  • How to connect servlet to mysql database

    Hi all,
    I am new to mysql. After many difficulty I have created a database with table in MySql. Now I want to connct it to a servlet. How do I do it?
    Can anyone tell me the steps, including the step to create MySql datasource
    thanks

    thanks for the reply. I know the basics of jdbc and can connect with sqlserver. Bt how to connect with Mysql? I mean what do I provide in dsn unless I create a MySql datasource. I cant find any tutorial which teaches how to create MySql datasource. Can you give me any link???
    thanks

  • How to connect to a MySQL database in another server

    Dear friends,
    I am using Oracle SQL Developer 1.5.3 and I need to connect to a MySQL database located in another server.
    I am trying to create a new connection, informing connection name, username and password. Supposing that "Hostname" is the IP server address, I click on "Choose database", but I always receive the following error message: "Status : Failure - Cannot connect to MySQL server".
    Please tell me what I should do to solve this situation. Thanks in advance.
    Best regards,
    Franklin

    You need to configure your mysql database to accept connection from your PC for the user you used.
    For example,
    GRANT ALL ON *.* TO 'someuser'@'somehost';
    FLUSH PRIVILEGES;

Maybe you are looking for

  • I got a new modem and imac says connected with the airport, but cant get a web page to come up on either safari or firefox

    I started having internet problems with all my devices in the house, ipod, imac, pc laptop, tablets, etc... found out after being on the phone with comcast for hours, they determined my modem that they supply was bad. So I have the new modem now and

  • Import packageless classes in a jsp : tomcat 5.0.16

    Hi all, I am trying to import a class, say one.class, which is stored in the /WEB-INF/classes folder of the webapplication into a jsp page. Like, <%@page import="one"%> I get the following error, C:\jakarta-tomcat-5.0.16\work\Catalina\localhost\test\

  • My itunes 11 keeps freexing

    hi since i have upgraded to itunes version 11 it keeps freezing on me all the time,ive un installed and reinstalled 5 times now and its still the same? it was working fine untill i got the new version i run windows 7 at the moment PLEASE HELP ME aaaa

  • URGENT :CCM not working

    Hi,   When I press on edit catalogue in the front end. I am getting page cannot be displayed error. Can anyone throw some light on this. Points will be rewarded for useful answers. Ingen

  • Why can't I read what I have written to the data socket server?

    Hi, I have a problem with DataSocket: I open a socket and in a cycle I read from the socket and write a boolean "TRUE" to the socket. But reading from the socket I always get a "FALSE" value back. Monitoring the socket from a second VI where a boolea