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,
Similar Messages
-
Hoe to connect java with mysql 5.0
I have installed the new Os. in that RHE-5 Os is there, now I want that java can connect ot mysql but , its not able connect with mysql so please guide me.
1) download mysql connector/J JDBC driver from mysql.com
2) put the driver jar somewhere where you can put it in the classpath of your application
3) use proper setup code to connect to the database (search google, tons of examples)
If at any step you have no clue what I am talking about, you need a good book to help you further. -
Hi
Can any one tell me how should i connect my java application with mySql database here is the small code which i written.
import java.sql.*;
class tryjdbc
public static void main(String[] args) throws Exception
try
Class.forName("com.mysql.jdbc.Driver").newInstance();
String connectionURL = "jdbc:mysql://localhost:3306/learn?user=root;password=";
Connection connection = DriverManager.getConnection(connectionURL, "root", "");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("Select ecode from emp");
while (rs.next())
System.out.println(rs.getString("ecode"));
catch (Exception e){
System.out.println(e);
Can any one please tell me the error there is no eror in compiling but at run time it gives error
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Thanks in advance
DhirajHi Dhiraj,
String connectionURL = "jdbc:mysql://localhost:3306/learn?user=root;password=";
Connection connection = DriverManager.getConnection(connectionURL, "root", "");
It seems to be your trying to pass twice of your properties details. One from through URL and another from by pasing the parameters on getConnection() method. Better to avoid to use two place in same application. and one more thing I want to confirm r u using "stable" Driver or "alpha" Driver.
Raju -
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'
I'm using the pre-installed versions of php and mysql under Mac OS X Server 10.4.4 running on a G4 and am unable to get anything involving mysql to work.
I ssh to the server and enter various commands in Terminal:
on typing "mysql" I get
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)
and on typing "mysqladmin version" I get
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/mysql/mysql.sock' exists!
On typing "sudo mysqld_safe" I get
Starting mysqld daemon with databases from /var/mysql
STOPPING server from pid file /var/mysql/MyServer.local.pid
070722 16:06:05 mysqld ended
/var/mysql/MyServer.local.err contains
070722 16:06:04 mysqld started
070722 16:06:04 [Warning] Setting lowercase_tablenames=2 because file system for /var/mysql/ is case insensitive
070722 16:06:04 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
070722 16:06:05 InnoDB: Starting log scan based on checkpoint at
InnoDB: log sequence number 0 43634.
/var/mysql has permissions 775.
The line
mysql.default_socket = /var/mysql/mysql.sock
is in /etc/php.ini
whereis mysqladmin ->
/usr/bin/mysqladmin
whereis mysql ->
/usr/bin/mysql
ls /var/mysql ->
MyServer.local.err
ib_logfile1
mysql
ib_logfile0
ibdata1
test
Can't find my.cnf or my.ini anywhere
Can't find mysql.sock anywhere
I'm trying to get a bug database running (mantis) under Mac OS X Server 10.4.4 that I can access from local clients.
I'm trying to follow directions at http://www.mantisbugtracker.com/manual/manual.installation.php
without knowing anything about mysql or php and I'm stuck on step 3:
"Next we will create the necessary database tables and a basic configuration
file."
I get a message saying
"Does administrative user have access to the database? ( Lost connection to MySQL server during query )"
I don't even know if following the mantis directions has resulted in the creation of a database or not. Where would it be?
Thanks for any help.
Intel iMac Mac OS X (10.4.10)I've just done a clean install of OSX Server and added the latest MYSQL packaged installer. Afterwards I found the lock file in /private/tmp/mysql.lock
The easiest way to solve this problem is to create a symbolic link so that the lock file appears to be in right place.
e.g.
cd /var
sudo mkdir mysql <== this assumes the directory is missing
cd mysql
sudo ln -s /private/tmp/mysql.sock mysql.sock
After this msql commands should work fine, and you've not fiddled with the security settings on users/groups.
HTH
Christian -
"Can't connect to local MySQL server through socket '/tmp/mysql.sock'"
Data Services=3.1
Repository=12.2.2.0000
Red Hat Enterprise 5
Designer,Job Server,Job Engine=12.2.2.3
After an unscheduled server reboot with DS up and running when trying to start a job in either Data Services Management Console or DS Designer getting the following:
"Can't connect to local MySQL server through socket '/tmp/mysql.sock'"
The mysql.sock have never been in /tmp and on the production server it does not exist there and the production server is up and running correctly. If a link is created to mysql.sock(/home/user/boedge31/bobje/mysql) the job will start but return this message:
"Cannot retrieve <Version> from the repository. Additional database information: <SQL submitted to ODBC data source <localrepo> resulted in error <MySQL ODBC 3.51 Driver mysqld-5.0.46-enterprise No database selected>. The SQL submitted is <select VERSION, SECURITYKEY, GUID from AL_VERSION where NAME = 'Repository Version'"
I checked and AL_VERSION and the Version field exist.
Before the shut down DS was working correctly and had no issues. My best guess is a part of the repository was corrupted during the unscheduled shut down. It seems like DS has "forgotten" some of the settings.
Any suggestions on a possible solution?The issue has been solved.
There was a bad path in $LD_LIBRARY_PATH.
Removed the path and DS started working again. -
Date Problem in Java with MySql
Hello
I am using Java with Mysql.I want to enter date in some in my format(YYYY:MM:DD:HH:MM:SS), this thing i have convert using format class and format class return date in String and iwwnat to insert this value in MySQL Table,So i want to know how can i convert String value in Date for Mysql is their inbuild function for converting string into date in mysql.
Regards
Anupam SUse PreparedStatement and SimpleDateFormat classes
http://onesearch.sun.com/search/onesearch/index.jsp?qt=%2BPreparedStatement+%2BSimpleDateFormat+&qp=siteforumid%3Ajava48&chooseCat=allJava&col=developer-forums&site=dev -
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 apexHi 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 oracle
can any body show me the code of how to connect java with oracle database.
thank youTo 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 ..."); -
Connecting JAVA with Video Card
Hai,...
Can someone tell me how to connect Java with a video card (like Matrox, dec-link, etc)?
Because i want to display a video using that video card to a TV monitor.
Is there any tutorial about this? and about connecting JAVA with other device?
Thank you,
BillyHai,...
Can someone tell me how to connect Java with a video card (like Matrox, dec-link, etc)?
Because i want to display a video using that video card to a TV monitor.
Is there any tutorial about this? and about connecting JAVA with other device?
Thank you,
Billy -
Hi,
I have a requirement in my project to connect Java with ABAP. I want to access ABAP tables from my java application. I am not sure but I think we can use SAP JDBC drivers to do that.
I found this link to connect JAVA with ABAP :
SAP DB JDBC Driver
My doubt from this link is where can I get the Host Name for the sandbox system I am using and what is the Database Schema name for the tables created using se11.
Regards,
PrateekHi
If you have direct connection to data base then you can use
the JDBC driver for the data base that is in use (We have oracle).
But usually you have to go through the application server this mean you have to use "SAP Java Connector" that connect to SAP using RFC .
Talk to your basis people.
Regards. -
MySQL problem -- ERROR 2002 Can't connect to local MySQL server
Not Sure if this would be a right forum for my problem...
I'm installing mySQL on my iBook, and thought that I have configured it. But then, after followring some instuctions from Adobe and Marc Liyanage sites, I have a problem to connect. This is what I've done in "TERMINAL"
~username$> cd /usr/local/mysql
mysql ~username$> sudo chown -R mysql data/
(asking for admin password)
mysql ~username$> sudo echo
mysql ~username$> sudo ./bin/mysqld_safe &
username-ibook-g4:/usr/local/mysql username$ Starting mysqld daemon with databases from /usr/local/mysql/data
STOPPING server from pid file /usr/local/mysql/data/roshaili-osmans-ibook-g4.local.pid
060611 16:31:30 mysqld ended
mysql ~username> /usr/local/mysql/bin/mysql test
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[1]+ Done sudo ./bin/mysqld_safe
mysql ~username>
When I typed ::
/usr/local/mysql/bin/mysqladmin -u root
(see that there's no password)
Then it displays:
/usr/local/mysql/bin/mysqladmin Ver 8.41 Distrib 5.0.22, for apple-darwin8.6.0 on powerpc
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Administration program for the mysqld daemon.
Usage: /usr/local/mysql/bin/mysqladmin [OPTIONS] command command....
-c, --count=# Number of iterations to make. This works with -i
(--sleep) only.
...... bla bla bla.....
Variables (--variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
count 0
force FALSE
compress FALSE
character-sets-dir (No default value)
default-character-set (No default value)
host (No default value)
port 0
.........bla bla....
ping Check if mysqld is alive
processlist Show list of active threads in server
reload Reload grant tables
refresh Flush all tables and close and open logfiles
shutdown Take server down
status Gives a short status message from the server
start-slave Start slave
stop-slave Stop slave
variables Prints variables available
version Get version info from server
roshaili-osmans-ibook-g4:~ roshailiosman$ >
-----------------finish-----------------
Does that mean that I'm connected to mySQL?
Does anybody how to connect to MYSQL from the terminal? Thanks.
iMac Mac OS X (10.4.6)
iMac Mac OS X (10.4.6)Your biggest 'issue' right now is that your mysqld process is stopping on you -- making a connection impossible.
Why it's bombing might be in a log .. try in mysql/data/usr.local.err .. and fix why itsbombing.
To connect to it it'll be : mysql -u root -ppassword -D database -
./mysqlshow: Can't connect to local MySQL server through socket '/tmp/mysql
hi all ,I install mysql on Solaris 10 at first it work fine , but after I restart my PC and go back again I got error on
./mysqlshow: Can't connect to local MySQL server through socket '/tmp/mysql
I google , but still not sure how to deal with it
Thank youI've just done a clean install of OSX Server and added the latest MYSQL packaged installer. Afterwards I found the lock file in /private/tmp/mysql.lock
The easiest way to solve this problem is to create a symbolic link so that the lock file appears to be in right place.
e.g.
cd /var
sudo mkdir mysql <== this assumes the directory is missing
cd mysql
sudo ln -s /private/tmp/mysql.sock mysql.sock
After this msql commands should work fine, and you've not fiddled with the security settings on users/groups.
HTH
Christian -
I just got an iPhone 4s, and I can not connect it with my iTunes from my previous account. I have already tried making another account, however it says that I have the wrong security code even though this is not true. What should I do?
Contact iTunes support. There's a link to it on the bottom of every page in the iTunes store.
-
An error occured when connecting java with Ms Access
Hello Everybody
I am a new developer in java and want to connect java with Microsoft Access
i am using JCreator LE
My code is to insert 3 records for 3 members and then save them in DB and retrieve the information
Here is the code
import java.sql.*;
public class Project3 {
public static void main(String[] args) {
try {
System.out.println("Beginning Connection");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String accessFileName = "Information";
String connURL = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ="+accessFileName+".mdb;PWD=";
Connection con = DriverManager.getConnection( connURL ,"","");
Statement stmt = con.createStatement();
System.out.println("Connection done successfully");
stmt.execute("Create table Member(Name String,ID Integer)");
stmt.execute("insert into Member values ('Joe','1234')");
stmt.execute(" select * from Member");
ResultSet rs=stmt.getResultSet();
if (rs != null)
while (rs.next()){
System.out.println("Name: "+rs.getString("Name")+ "ID: " + rs.getString("ID"));
stmt.close();
con.close();
catch (Exception e) {
System.out.println("An error Occurred in Connecting with the DB " );
}and the error is
Beginning Connection
Connection done successfully
An error Occurred in Connecting with the DB
it didn't insert information in the DBWell, thank u i have traced the error and fx it
but
how to modify the code and keep the user entering 3 values and search for the entered values??
Here is the correct code
import java.sql.*;
public class Project3 {
public static void main(String[] args) {
try {
System.out.println("Beginning Connection");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String accessFileName = "jdbc:odbc:Project";
String connURL = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ="+accessFileName+".mdb;PWD=";
Connection con = DriverManager.getConnection( accessFileName);
Statement stmt = con.createStatement();
System.out.println("Connection done successfully");
stmt.execute("Create table Member(Name String,ID Integer)");
stmt.execute("insert into Member values ('Joe','1234')");
stmt.execute(" select * from Member");
ResultSet rs=stmt.getResultSet();
if (rs != null)
while (rs.next()){
System.out.println("Name: "+rs.getString("Name")+ "ID: " + rs.getString("ID"));
stmt.close();
con.close();
catch (Exception err) {err.printStackTrace();}
} -
Unable to connect JAVA with Oracle
I have jdk1.6 and oracle installed on my machine but unable to connect java with database
have classes12.jar and ojdbc14.jar
my environmental variables in respect to this are :
JAVA_HOME= C:\Java\jdk1.6.0_04
JRE_HOME=C:\Java\jdk1.6.0_04
PATH=J:\oracle\ora92\lib;
J:\oracle\ora92\bin;
C:\Program Files\Oracle\jre\1.3.1\bin;
C:\Program Files\Oracle\jre\1.1.8\bin
CLASSPATH=J:\oracle\ora92\jdk\jre\bin\JdbcOdbc.dll;
J:\oracle\ora92\jdbc\lib\classes12.jar;
J:\oracle\ora92\jdbc\lib\ojdbc14.jar
The code is
import java.sql.*; public class dat1 { public static void main(String[] args)throws SQLException,ClassNotFoundException { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Class.forName("com.oracle.jdbc.OracleDriver"); } catch (ClassNotFoundException e) { System.out.println("unable to load driver"); return; } } }
the error message is
Error in thread "main" java.lang.NoClassDefFoundError
Please Help Me
Thanks For Reading
Thanks a lot in Advance For your ANSWERSmaybe if you asked nicely instead of ordering people around we might tell you.
As it is all you're going to hear is that you don't need both those jars, as they contain different versions of the same driver.
I'm not going to tell you which you need, as you should have the documentation to tell you that. But then you also should have the documentation to tell you how to set your classpath properly and you failed to read that too.
Maybe you are looking for
-
How to "enter" a text field on a website that doesn't have an enter button?
Hi All, I wanted to know I can press "enter" in a text field on a website that doesn't have an enter button. I have used the following to help me code (i.e. login, enter values into fields). https://decibel.ni.com/content/docs/DOC-25396 The above lin
-
Hi, I had tried to replace the old DVD/CDRW with the above UJ-830B ( FW: 1.50, HW: 1.00) but the result was IDE error. It is not recognize it in Windows at all. I have tried to solder the contact 48 and 49 but result is the same. How can I make to wo
-
White blank popup permanent on screen front
white rectangle comes on screen with some web sites and stays in front of all programs and cannot be remove unless I reboot. Not all web sites cause the popup. When right click is picked on the square it allows you to go to the Flash Player 9 web sit
-
Variant Configuration optimization
Hello Expert, I would like to know how we can optimize large VC setup I mean there are more than 1800 characteristics used in 500+ dependencies like preconditon, selection condition,procedure ,constraint. We used variant table and different function
-
Why can't I or should I say, how can I, view the txt messages that I've sent? I love the conversation view but I just wanna see how many I've sent in total. Any ideas? Thanks in advance