Establishing connection to MySQL server/database

Hi! I've got a question about subj. Here is my code:
import java.sql.*;
import java.util.*;
class SQLDB {
    int db_port;
    String db_url, db_name, db_table, db_user, db_passwd;
    public void dbConnect() throws SQLException {
        Connection con = new Connection();
        Properties prop = new Properties();
        prop.put("charSet", "utf8");
        prop.put("user", db_user);
        prop.put("password", db_passwd);
        con = DriverManager.getConnection(db_url, prop);
}NetBeans says that Connection (Connection con = new Connection()) object is abstract and can't be instantiated. Can anyone suggest me what to do?

Agree :) But faced another problem. I made this part of code after reading various info on this matter:
package dbCinema;
import java.sql.*;
//import java.util.*;
class SQLDB {
    private int db_port;
    private String db_url, db_name, db_user, db_passwd;
    private Connection con = null;
    private Statement db_query = null;
    private ResultSet rs = null;
    SQLDB(String dburl, String dbname, String dbuser, String dbpasswd, int dbport) {
        db_url = dburl;
        db_name = dbname;
        db_user = dbuser;
        db_passwd = dbpasswd;
        db_port = dbport;
    public void dbConnect() {
        String url;
        //url = "jdbc:mysql://" + db_url + ":" + db_port + "/" + db_name;
        url = "jdbc:mysql://" + db_url + "/" + db_name;
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
            con = DriverManager.getConnection(url, db_user, db_passwd);
            if (!con.isClosed())
                System.out.println(db_name + ": connection established.");
        } catch (SQLException e) {
            System.err.println("Exception: " + e.getMessage());
        } catch (ClassNotFoundException e) {
            System.err.println("Exception: " + e.getMessage());
    public void dbQuery(String query) throws SQLException {
        db_query = con.createStatement();
        rs = db_query.executeQuery(query);
        while (rs.next()){
            System.out.println(rs.getString(3));
    public static void main(String args[])  {
        SQLDB comm = new SQLDB("localhost", "cinema", "", "", 3306);
        try {
            comm.dbConnect();
            comm.dbQuery("SELECT * from t_movies WHERE id=1");
        } catch (SQLException e) {
            System.err.println("Exception: " + e.getMessage());
}And having this error as a result of running this class:
> "java" SQLDB
java.lang.NoClassDefFoundError: SQLDB (wrong name: dbCinema/SQLDB)
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(Unknown Source)
     at java.security.SecureClassLoader.defineClass(Unknown Source)
     at java.net.URLClassLoader.defineClass(Unknown Source)
     at java.net.URLClassLoader.access$000(Unknown Source)
     at java.net.URLClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main"
Process Exit Code: 1
Time Taken: 00:01I've downloaded and installed into my java jre/lib/ext folder this driver (mysql-connector-java-5.1.6-bin.jar) to make connection possible. What's wrong?
Edited by: Utah on Aug 14, 2008 12:12 PM

Similar Messages

  • Database error #2002 can not connect local mysql server to socket through '/var/run/mysqld/mysqld.sock'(2) on mac os x 10.9.2

    Dear Fellas:
    I received "database error #2002 can not connect local mysql server to socket through '/var/run/mysqld/mysqld.sock'(2)" on mac os x 10.9.2.
    mysql info:
    ps -ef | grep mysql
        0    66     1   0 11:06AM ??         0:00.04 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql
       74   225    66   0 11:06AM ??         0:02.50 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/Chuans-MacBook-Pro-2.local.err --pid-file=/usr/local/mysql/data/Chuans-MacBook-Pro-2.local.pid --socket=/var/run/mysqld/mysqld.sock
      501   952   947   0  3:52PM ttys000    0:00.00 grep mysql
    Please help!!

    Fascinated and guessing:
    Something related to sock(2) because that's not part of your copied info. I'm thinking you've doubled up on sockets and the second socket doesn't exist, meaning you should be connecting to the first socket "mysqld.sock" whether automatic or not.
    I've only used GUI tools on purpose, so does this mean you've already got MySQL running and you tried to launch it again manually? Perhaps you already have one instance of a db and you're trying to launch a second instance, and the two can't coexist with a single user local db?
    Assuming this is all local, I'd shut down the db service and restart it, out of hand. I've seen similar messages when I set the db to start up on boot, and it didn't finish shutting down when I tried to restart it manually. Usually the GUI won't let me turn it on because it reports it's already running, but in that case it hadn't finished performing what the GUI was reporting.
    Just speculating.

  • Unable to open any websites from the search engines. the ones I have tried are google, yahoo and ask. They opened until recently. The popup says" Firefox can't establish connection to the server." Ask worked last night but is not working now.

    When I try to open a web site from one of the search engines a pop up shows stating that Firefox can't establish connection to the server. I can't open any websites through any of the search engines.

    Do a malware check with some malware scanning programs.<br />
    You need to scan with all programs because each program detects different malware.<br />
    Make sure that you update each program to get the latest version of their databases before doing a scan.<br />
    * http://www.malwarebytes.org/mbam.php - Malwarebytes' Anti-Malware
    * http://www.superantispyware.com/ - SuperAntispyware
    * http://www.microsoft.com/windows/products/winfamily/defender/default.mspx - Windows Defender: Home Page
    * http://www.safer-networking.org/en/index.html - Spybot Search & Destroy
    * http://www.lavasoft.com/products/ad_aware_free.php - Ad-Aware Free
    See also:
    * "Spyware on Windows": http://kb.mozillazine.org/Popups_not_blocked

  • Unable to connect to sql server database

    i run on CMD:
    aspnet_regsql -C "Data Source  =Davidchamoun/sqlexpress : intergrated security= true" -ssadd -sstype p
    i got 
    a network-related or instance-specific error occurred while establishing a connection to sql server. the server
    was not found or was not accessible. verify that the instance name is correct and that sql server is configured to allow remote connections. (provider: SQL Network interfaces . error: 25 – connection string is not valid
    unable to connect to sql server database.
    im using sql sever 2012 express, microsoft visual studio web 2008 express.
    please help me.

    i run it as :
    aspnet_regsql -C "Data Source =Davidchamoun\sqlexpress : integrated security= true" -ssadd -sstype p
    i got the same error :
    an error has occurred . details of the exception:
    a
    network-related or instance-specific error occurred while establishing a connection to sql server. the server was not found or was not accessible. verify that the instance name is correct and that sql server is configured to allow remote connections. (provider:
    SQL Network interfaces . error: 25 – connection string is not valid
    unable to connect to sql server database.
    im using also windows 8.1
    pls help me
    ty for ur reply

  • SQL Server Reporting services. failed to establish connection with project server. verify the url is correct.

    Dear All,
    I'm working on reporting of Project Server 2010, while configuring SQL SERVER REPORTING SERVICES faced issue after two complete days of troubleshooting along with this gone through plenty of forums, unable to figure out any solution. So finally posting on
    technet in order to find solution.
    ISSUE/PROBLEM:
    At initial configured the SQL REPORTING CONFIGURATION to sharepoint integrated database (SQL SERVER is installed on seperate machine), change the service to Domain Account and also installed sharepoint add in on server story was fine at this point. Furthur
    moving to SHAREPOINT ADMIN console and while configuring the Sharepoint Integrated Reporting continuously facing this error:
    Failed to establish connection with report server. . . . (Snapshot is attached for your further reference).
    My point of concern is that whenerver i try to open the REPORT SERVER URL on project server machine it prompts me to enter username and password but whenever i insert the domain credentails it didnt accept though it can be accesible by using the credentials
    of Local Admin of sql server machine. So i wana come to know whether its permission issue if yes then where i should mention the domain credentials.? 
    REGARDS DANISH DANIE

    Dear Paul,
    I am able to open the URL (http://psdb/ReportServer )using
    domian credential and page open with these contents
    Reporting Services Error
    The configuration parameter SharePointIntegrated is set to True but Share Point Object Model cannot be loaded
    Second,
    Configured the SPN on domain controller , performed the steps required to change the AUTHENTICATION in rsreportserver.config
    file also done the registry settings to disable the loop back settings.
    Same error still ! .... what should i do now ??? 
    REGARDS DANISH DANIE

  • Connecting To Mysql Server

    Hi all,
    In SAP is it possible to connect a mysql database and get data from? Our resources(machines) have a server and this server keeps data about production. And i want to connect this db server and get data with my syntax, constraints? Can i directly do that in SAP ?
    Regards,

    I only want to connect the mysql server and get some of data from tables on mysql and save this data in the table of SAP system ? How can i do that ?
    Regards,

  • Trying to edit a wordpress then in dreamweaver cc with mamp but things don't work out. dreamweaver can't establish connection with my server.

    Trying to edit a wordpress then in dreamweaver cc with mamp but things don't work out. i've been searching through the net bt i didn't find an answer. i've followed many tutorials and did exactly the things that was asked but dreamweaver can't establish connection with my server. here's a few pics with the preferences i'm trying to establish a connection. Note that i tried it without "localhost" in the weburl. mamp is running with apache and mySql. Anyone please.

    Hi Gareth,
    See if the following link helps:
    <a href="https://www.sdn.sap.com/irj/sdn/thread?threadID=174271">https://www.sdn.sap.com/irj/sdn/thread?threadID=174271</a>
    Bye
    Ankur

  • SAPextractor error using MySQL Server database in OrgChart

    Hi Experts:
    We are now using MySQL Server database for Nakisa OrgChart 2.0. Source-SAP details were specified and test connection to database is successful.  We encountered the following errors when we performed the extraction.
    Processing Function Read Table Function/BAPI Downloading Tables Organizational Assignment
    No Tables were downloaded for Read Table Function/BAPI . Function is flagged as critical.Terminating Extraction.
    Processing Stopped ! ! !
    Downloading from SAP completed.
    Processing Completed.
    From CDS.log, we got the error message below:
    ERROR: Schema : tableName = OrgUnitHierarchy; : Source {.Net SqlClient Data Provider}: Message {Invalid object name 'OrgUnitHierarchy'.}
    ERROR: Schema : tableName = OrgUnitHierarchy; : Source {.Net SqlClient Data Provider}: Message {Invalid object name 'OrgUnitHierarchy'.}
    ERROR: Schema : tableName = OrgUnitHierarchy; : Source {.Net SqlClient Data Provider}: Message {Invalid object name 'OrgUnitHierarchy'.}
    ERROR: Sap Authentication : Source {SAP.Connector}: Message {An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)}
    Can you help us to check how to fix this error. In addition, we would also like to know how to configure XML files required for this installation.
    Thanks.
    Angelo
    Accenture
    SAP Basis

    Hi Angelo,
    Is this still an issue for you? If so can you let me know if you are using 32-bit or 64-bit server and what version you are using of TVN?
    All the best,
    Luke

  • Cannot connect to SQL Server databases

    All of a sudden I can't connect to SQL server databases from
    my local machine. The databases are on a web server. It just
    started happening, and I never had a problem with it before. I
    can't connect to them in the coldfusion administrator, and I can't
    connect to them using ODBC DSN's either. Has anyone ever run into
    this before? I didn't change anything in the cf admin, and I
    certainly didn't change any logins or passwords in SQL
    Server.

    I've been experiencing a similar problem. Everything was fine
    but I had to reboot CF 8.01.
    After the reboot all the datasources are very slow to respond
    and we get lots of errors of the form :
    Timed out trying to establish connection
    A non-SQL error occurred while requesting a connection from
    blah
    Timed out trying to establish connection
    A non-SQL error occurred while requesting a connection from
    blah
    Everything is working but very slow on database queries. This
    happened a couple of months ago when we last
    rebooted and then it went away.
    Going to have a look for a new JDBC driver from adobe and see
    if that helps ....

  • Plz help me--error connecting to MySQL server

    While trying to connect to the MySQL server database,
    SqlConn = DriverManager.getConnection("jdbc:mysql://" + "database_server_addr/database_name?user=kiosk&password=!xyzabc");
    I get the following error.
    Error while connecting to mysql
    Communication link failure: null
    Notice the ! symbol(exclamation mark) present in the connection string above for the password value i.e., !xyzabc
    Is the problem with the ! symbol in my password, coz I am able to connect
    if I changed my password omitting the ! symbol. But I would like to connect with the ! symbol in the password. Any quick help is appreciated.
    Thanks,
    Bussa.
    [email protected]

    specify the database Server address, you can't do it with the "HTTP URL"
    String url = "jdbc:mysql://xxx.xxx.xxx.xxx";
    Class.forName("mySql spec");
    Connection con = DriverManager.getConnection(url,"user", "pass");

  • *DAC Server connection "Error - can't establish connection to DAW Server"

    Hi there,
    I'm experiencing trouble with the Oracle Data Warehouse Administration Console (DAC) server connection hanging in my Oracle BI Apps 7.9.6 install.
    Architecture*
    Applications Server - Machine A (Oracle Connection Services 10g R2 + Informatica 8.6.0 & HotFix 4.0 + DAC 10.1.3.4.1 services) = Linux RHEL 64-bit
    Database Server - Machine B (Oracle BI Apps Data Warehouse OBAW + DAC Repository + Informatica Repository) = Linux RHEL 64-bit
    Client - Machine C (BI Apps 7.9.6 + Informatica 8.6.0 & HotFix 4.0 client + DAC 10.1.3.4.1 client) = Windows x86 32-bit)
    Issue*
    After successfully following the Oracle Business Intelligence Applications Installation Guide for Informatica PowerCenter Users Version 7.9.6 (E14217-01) documentation I get to section 4.13 Configuring the DAC Server and I cannot create a successful connection to the DAC Server from the Data Warehouse Administration Console on my client machine.
    I can confirm that I have started the DAC services on the Linux server with the . ./startserver.sh command. The icon on the Data Warehouse Administration Console turns Orange (Idle), but when I double click the icon a message box appears with the title "Server Log" but seems to hang.
    If I stop the DAC services on the Linux server with the . ./stopserver.sh command the Server Log message box closes and a new message box appears stating:
    *"Error: can't establish connection to DAW Server!"*
    I have tried using the IP address and the actual server name as defined in the Hosts file as the DAC Server Host in the DAC System Properties but I receive the same error message.
    I can also confirm that I ran the serverSetupPrompt.sh shell script successto configure the connection between the DAC Server and the DAC Repository.
    Any suggestions or help greatly appreciated.
    Kind Regards,
    Gary.

    Hi Gary,
    If you have the Orange icon then your client is connected to the DAC server. (If it's red then it's not, and if it's green it's connected and an execution plan is running).
    If you have never run any DAC jobs (and if you're just doing the installation then you won't have I guess) then your log will be blank and you'll just get a blank log window.
    Have you got any evidence that your DAC server isn't running other than the Log won't download properly?
    Obviously if you stop the DAC server then you're going to get an error that the client can't connect to the server :-D
    If I were you I'd continue with the installation guide, as it sounds like things are working as they should.
    BTW don't forget to mark this and other responses to your posts as helpful/correct as appropriate :)

  • ERROR#: 2002 can't connect to MySQL server through socket '/var/mysql/mysql.sock'

    I was following this adobe article (
    http://www.adobe.com/devnet/dreamweaver/articles/php_macintosh.html)
    to set up PHP and MySQL and connect a MySQL database to dreamweaver
    in Mac OS 10.4.8 and I kept getting:
    "Can't connect to MySQL server through socket
    '/var/mysql/mysql.sock' ERROR#: 2002".
    After a lot of searching I came across
    this
    article which said that there was an error in the PHP and MySQL
    connection or something.
    Anyway all I had to do was type (in a TERMINAL window):
    $ sudo mkdir /var/mysql
    $ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
    and that fixed the problem, otherwise the adobe article
    worked very well.
    Check out the "this article" link to get the fix straight
    from the horse's mouth.

    I was following this adobe article (
    http://www.adobe.com/devnet/dreamweaver/articles/php_macintosh.html)
    to set up PHP and MySQL and connect a MySQL database to dreamweaver
    in Mac OS 10.4.8 and I kept getting:
    "Can't connect to MySQL server through socket
    '/var/mysql/mysql.sock' ERROR#: 2002".
    After a lot of searching I came across
    this
    article which said that there was an error in the PHP and MySQL
    connection or something.
    Anyway all I had to do was type (in a TERMINAL window):
    $ sudo mkdir /var/mysql
    $ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
    and that fixed the problem, otherwise the adobe article
    worked very well.
    Check out the "this article" link to get the fix straight
    from the horse's mouth.

  • Failed to Establish connection with SQL Server

    hi I have configured odbc settings and when i connect the sql from essbase i got the error :Failed to Establish connection with SQL Server .please hepl me on this
    and please give me step by step process for how to resolve thi issue.and give me detail step by step from starting onwards.
    appreciate your Help,
    Thank u
    Subbu.

    Steps:
    1. Test database connection from Essbase server through SQL Command. This gives you whether you are able to connect to Database from Essbase server.
    2. Create ODBC Connection: System DSN>Add>Select correct driver (Oracle in ...) >give Datasource (any name), Description (Any), TNS Service Name (user SID name), User name (Database user name)
    3. Test Connection. if successful, you can use this ODBC to get the data.
    4. Open rules file, go to FILE>Open SQL
    5. Provide Essbase server, Application, Database names
    6. Select SQL Data Source from the list (ODBC defined in step2)
    7. Enter tested SQL Query(which is tested at SQL command or "sysdate from dual" ) in select box. NOTE: Remove select word from query. You can ignore from and where clauses, all you can include in select block.
    8.Click OK/Reteive data
    Rao

  • Connection to db rejected.Cannot connect to MySQL server

    here is the excaption
    connectToDb:02 - connection to db rejected.Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.BindException)
    and her is the class
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class DBconnect
    {  final static private String _url        = "jdbc:mysql://localhost:3306/diamonds";     //final static private String _driver     = "sun.jdbc.odbc.JdbcOdbcDriver";
        //final static private String _url        = "jdbc:odbc:diamonds";     //final static private String _driver     = "sun.jdbc.odbc.JdbcOdbcDriver";
        public Connection     _con                     = null;
         //private static Driver          driver          = null;
         private static Properties     properties     = null;
         Statement stmt                                 = null;
         public PrintStream     out;
            **connectToDb **
            public void connectToDb()        throws IOException
            //connect to the server and open the database
             try{
                   Class.forName("org.gjt.mm.mysql.Driver");
                   //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   //driver = (Driver)Class.forName (_driver).newInstance();
                   properties = new Properties();
                properties.put("user","sa");
                   properties.put("password","");
            catch (ClassNotFoundException e)
                   System.out.println("class not found:");
                   e.printStackTrace();
              catch (Exception e) {
                        e.printStackTrace();
                 throw new IOException("connectToDb:01- JDBC driver not found."+e.getMessage());
         synchronized void open()throws Exception
              try
                   if(_con == null)
                        try
                             _con = DriverManager.getConnection(_url,properties);
                             //_con = driver.connect(_url,properties);
                        catch (SQLException e)
                             e.printStackTrace();
                             System.out.println("connectToDb:02 - connection to db rejected."+e.getMessage());
                        stmt = _con.createStatement();
              catch (Exception e)
                   e.printStackTrace();
                   System.out.println("connectToDb:02 - connection to db rejected."+e.getMessage());
         synchronized void close()
              try
                   if(_con != null)
                        if(!_con.isClosed())
                             stmt.close();
                             _con.close();
                             _con = null;
              catch (Exception e)
                   System.out.println("es:fail to close connection!!");
    }the problem occars when there are a lot of queries that the project is sending to the DB (about 10000) the last half queries fails and send an excaption .
    after 2 minutes the system seems like working fine.
    I am stack with this problem about a year and cann't resolve it.
    any idea????
    regards
    amnon m

    well...new it seems to work fine, but is it ok to
    keep connection open for good ???
    isn't there any other alternative ???I am bit confused are you pooling the connections?
    If so, actually the connections will not always stay open.. they will time out after a while when they are not in use but to specifically answer your question.. how could it possible be a bad thing. If the server/your app was getting bogged down with opening and closing connections then pooling solves this..
    Finally as to your question of the alternatives... if the problem was opening and closing connections and reusing them through a pool solved this then I think the answer is no. If you don't like a specific part of the way the pool works it is probably configurable in some way and you could always implement your own pool.. although I wouldn't overly recommend that. The bottom line is that you need to keep your connections open for reuse.. pooling is the simplest way to achieve this.. but no there is no alternative to keeping your connections open if you are having the load problems you described.

  • Sql developer won't connect with SQL server database on cluster

    Hello,
    I have a microsoft SQL server database on a windows cluster. Name for this cluster is like XXX/YYY
    When I try to connect to this database with SQL developer, I get a failure, mentioning:
    "Status : Failure -Cannot connect to Miscrosoft SQL Server on XXX/YYY"
    As far as I know, I have installed the correct jtds driver (version 1.2.5), since I can connect to sql server databases on single server hosts.
    Does anyone know how to connect to databases on windows clusters?
    Edited by: Ingmar on Jan 16, 2012 4:08 PM
    Edited by: Ingmar on Jan 16, 2012 4:22 PM

    Hi Ingmar,
    Try this is in the port box
    1433/dbname;instance=YYY
    dbname can be omitted
    -Turloch
    SQL Developer team
    1/Giving an instance name in SQLDeveloper connection to SQL Server (from August 2011)
    MS SQL Server Connection
    The correct syntax to deal with this is in the port box
    1433/dbname;instance=instance
    dbname can be omitted
    2/cluster configuration (uses instance name)
    http://stackoverflow.com/questions/1160024/jdbc-connect-string-for-sql-server-cluster
    where vvv\iii is the cluster address: jdbc address is:
    "jdbc:sqlserver://vvv;instanceName=iii"
    3/jtds url details available in
    http://jtds.sourceforge.net/faq.html

Maybe you are looking for