Need help on java with mysql...
I want to make application that will use mysql as database. I have downloaded mysql connector j but i'm confuse about how to install it to jdk. for reference, i'm using windows xp, phptriad that have mysql 4.1.
After that, how do I connect my application to the database?
please help...
Thanks before...
Have a look at this tutorial:
http://java.sun.com/docs/books/tutorial/jdbc/index.html
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 advancehey 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, -
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 -
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. -
Problems conecting java with mysql
Hi, im workin' with mysql-connector-java-3.1.12 and it work on debug runtime but not when i access the .jar of the project.
the code of conection is:
try
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url,login,password);
con.setAutoCommit(false);
catch (Exception e)
JOptionPane.showMessageDialog(null,"error en " + e.getMessage());
there is no problems with code, it works!!, but i don't know what to do about of conection in the .jar
I apreciate some help with this, Thankkkssss!!!Hi, im workin' with mysql-connector-java-3.1.12 and
it work on debug runtime but not when i access the
.jar of the project.Huh?
the code of conection is:
try
lass.forName("com.mysql.jdbc.Driver").newInstance();
con =
DriverManager.getConnection(url,login,password);
con.setAutoCommit(false);This is probably wrong. Unnecessary in this case - you aren't doing any writes.
catch (Exception e)
OptionPane.showMessageDialog(null,"error en " +
e.getMessage());This is foolish code. You don't need Swing or a dialog box. You're printing less information than is available. Better to print the entire stack trace.
is no problems with code, it works!!, Plenty of problems, really, regardless of whether it "works".
You don't post your URL. That would help.
but i don't
know what to do about of conection in the .jar
I apreciate some help with this, Thankkkssss!!!Put in the CLASSPATH, of course. NOT a system environment variable, either. javac.exe and java.exe ignore it. Use the -classpath option.
% -
i am using JSP in Linux Platform. when i connected to mysql with mysql driver for odbc by using the following code,
import java.sql.*;
public class TestMysql
public static void main(String args[]) {
try {
Connection con;
String connStr = "jdbc:mysql://localhost/test?user=root&password=mysql";
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
System.out.println("OK");
con = DriverManager.getConnection( connStr );
System.out.println("Again OK");
catch( Exception x )
x.printStackTrace();
i got the following exception
OK
java.sql.SQLException: Error during query: Unexpected Exception: java.io.CharConversionException message given: null
Nested Stack Trace:
** BEGIN NESTED EXCEPTION **
java.io.CharConversionException
STACKTRACE:
java.io.CharConversionException
at gnu.gcj.convert.Input_iconv.read(char[], int, int) (/usr/lib/libgcj.so.5.0.0)
at java.lang.String.init(byte[], int, int, java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at java.lang.String.String(byte[], int, int, java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at com.mysql.jdbc.SingleByteCharsetConverter.SingleByteCharsetConverter(java.lang.String) (Unknown Source)
at com.mysql.jdbc.SingleByteCharsetConverter.initCharset(java.lang.String) (Unknown Source)
at com.mysql.jdbc.SingleByteCharsetConverter.getInstance(java.lang.String, com.mysql.jdbc.Connection) (Unknown Source)
at com.mysql.jdbc.Connection.getCharsetConverter(java.lang.String) (Unknown Source)
at com.mysql.jdbc.StringUtils.getBytes(java.lang.String, java.lang.String, java.lang.String, boolean, com.mysql.jdbc.Connection) (Unknown Source)
at com.mysql.jdbc.Buffer.writeStringNoNull(java.lang.String, java.lang.String, java.lang.String, boolean, com.mysql.jdbc.Connection) (Unknown Source)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(com.mysql.jdbc.Statement, java.lang.String, java.lang.String, com.mysql.jdbc.Buffer, int, com.mysql.jdbc.Connection, int, int, boolean, java.lang.String, boolean) (Unknown Source)
at com.mysql.jdbc.Connection.execSQL(com.mysql.jdbc.Statement, java.lang.String, int, com.mysql.jdbc.Buffer, int, int, boolean, java.lang.String, boolean, boolean) (Unknown Source)
at com.mysql.jdbc.Connection.configureClientCharacterSet() (Unknown Source)
at com.mysql.jdbc.Connection.initializePropsFromServer() (Unknown Source)
at com.mysql.jdbc.Connection.createNewIO(boolean) (Unknown Source)
at com.mysql.jdbc.Connection.Connection(java.lang.String, int, java.util.Properties, java.lang.String, java.lang.String) (Unknown Source)
at com.mysql.jdbc.NonRegisteringDriver.connect(java.lang.String, java.util.Properties) (Unknown Source)
at java.sql.DriverManager.getConnection(java.lang.String, java.util.Properties) (/usr/lib/libgcj.so.5.0.0)
at java.sql.DriverManager.getConnection(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at TestMysql.main(java.lang.String[]) (Unknown Source)
** END NESTED EXCEPTION **
at com.mysql.jdbc.Connection.execSQL(com.mysql.jdbc.Statement, java.lang.String, int, com.mysql.jdbc.Buffer, int, int, boolean, java.lang.String, boolean, boolean) (Unknown Source)
at com.mysql.jdbc.Connection.configureClientCharacterSet() (Unknown Source)
at com.mysql.jdbc.Connection.initializePropsFromServer() (Unknown Source)
at com.mysql.jdbc.Connection.createNewIO(boolean) (Unknown Source)
at com.mysql.jdbc.Connection.Connection(java.lang.String, int, java.util.Properties, java.lang.String, java.lang.String) (Unknown Source)
at com.mysql.jdbc.NonRegisteringDriver.connect(java.lang.String, java.util.Properties) (Unknown Source)
at java.sql.DriverManager.getConnection(java.lang.String, java.util.Properties) (/usr/lib/libgcj.so.5.0.0)
at java.sql.DriverManager.getConnection(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at TestMysql.main(java.lang.String[]) (Unknown Source)
i have the database, hello.
The same code works well in Windows, But in Linux, the above exception.
By using the username root and password mysql , i can connect to mysql directly from the mysql prompt.
Pls help me..
I have already put the query 'access denied problem in Mysql' some day before. from the reply, i made some changes in user table(ie. set the password for [email protected].).After this change, this new Exception came..
The structure of my mysql.user table is
# host user password
1 localhost root 68d4f47c49a579c9
2 localhost.localdomain root 68d4f47c49a579c9
3 localhost.localdomain
4 localhost
Pls help me.
Edited by: SUMESHBABU_R on Sep 30, 2007 11:36 PMWell, at least the trace tells me that this issue is to be tracked back to the core of the MySQL JDBC driver and the Linux's implementation of JVM. It might be worth the effort to post this issue at their website/forum/issuetracker. It might also be worth the effort to tryout the newer MySQL JDBC driver 5.1, as it is written specific for JDK 6.0 (while MySQL JDBC driver 5.0 is targeted at JDK 5.0).
-
i Need some help in Java Script,
am using the following code :
<script type="text/javascript">
var newwindow;
function poptastic(url)
newwindow=window.open(url,'name','height=300,width=400,left=100, top=100,resizable=yes,scrollbars=yes,toolbar=yes,status=yes');
if (window.focus) {newwindow.focus()}
else {newwindow.close()}
// if (window.focus) {newwindow.focus()}
</script>
In HTML,
thWorld Environment
Day, June 5<sup>th</sup>,2005
Am using onmouseover event, so that when my mouse in on the link, popup is opened....and when my mouse is out of the link, the new window should b closed....
but according to the above code, the new window is opened but have to close it manually....
Is there any other way to close the popup when my mouse is out of the linkPrawn,
This is not really a good way to make friends. With the cross posting and the posting in a wrong forum anyway thing you have going.
Please kindly take your question to an appropriate JavaScript forum.
Have a happy day.
Cross post from http://forum.java.sun.com/thread.jspa?messageID=3797201 -
I'm a beginner who's just enabled PHP and Web Server on my Mac OS X 10.5.
But I'm stuck with MySQL. I really need some help with installing MySQL.
It says it's pre-installed on Application > Server file, but I don't see Server File in Anywhere.
So,I installed manually on dev.mysql.com.
But then, I was supposed to go to usr/local file, but I don't see Local file either!
I tried to create my own local folder and put mysql installed files in, but when I
typed sudo chown -R mysql data/, on Terminal, it says No such file.
Can anyone please help me install MySQL on my Mac?Try this
-
Need help on Java in sound application
A good day to everyone here,
I need help on using Java.My project is mainly manipulating WAV sound files with Java. There is some problem.I hope you all can help me. I couldn't find much info about Java in sound manipulating,sample coding or something like that. I need to find the command to
1) Find each sampling point value in a sound file.
2) Find the number of sampling point and the average value of the all the sampling point.
3) Record the sound file in a different bit rate format.
I dont know how to go about it.I really hope you all can help me, or direct me to any resources that may help me. Your help is very much appreciated.
Thank you very much....i found this coding in a website n i not very sure that i understand it.
can anyone tell me if i can find the sample point value of a sound file with this coding (byte[] source is byte array of the sound file).
thanks...for all the help
public byte[] executeAmplitudeTransformationInternal(byte[]
source)
int[] sampleArray = getSampleArray(source);
int[] newSampleArray = executeTransformation(sampleArray);
//convert 16 bit samples back to 8 bit byte[]
return getByteArray(newSampleArray);
public int[] getSampleArray(byte[] eightBitByteArray) {
//create an array 1/2 the size (since every 2
//8bit samples makes 1 16bit sample)
int[] toReturn = new int[eightBitByteArray.length];
int index = 0;
for (int t = 0; t < eightBitByteArray.length; t += 2) {
//read the high bit
int low = (int) eightBitByteArray[t];
//read the low bit
int high = (int) eightBitByteArray[t + 1];
//bit shift the high bit 8 bits to the left and
// "And" the low bit against 255 to drop any
//sign extended data in the top 8 bits.
//refer to the tutorial for more clarification
toReturn[index] = (high << 8) (low & 0x00ff);
index++;
return toReturn;
public byte[] getByteArray(int[] sampleArray) {
//create a new byte[] twice as big as the sample array
//because it takes two 8-bit bytes to represent one
//16-bit sample
byte[] toReturn = new byte[sampleArray.length * 2];
int index = 0;
for (int t = 0; t < sampleArray.length; t++) {
int sample = sampleArray[t];
//this places the low byte in the array.
//the downcasting automatically lops off the high byte
toReturn[index] = (byte) sample;
index++;
//this byte shifts the sample 8 bits to the right
//this puts the old high byte in the position of the low byte.
//this way the high byte remains after the downcasating from
//an int to a byte
toReturn[index] = (byte) (sample >> 8);
index++;
return toReturn;
public int[] executeTransformation(int[] sampleArray) {
//create a clone sample array
int[] newSampleArray = new int[sampleArray.length];
//apply algo to each sample
for (int t = 0; t < sampleArray.length; t++) {
int result = (int) (sampleArray[t] );
//add the sample
newSampleArray[t] = result;
return newSampleArray; -
Need help to start with some file and text manipulation
Hello script mavens,
I need help with starting a script that does the following:
-within a base folder it takes an inventory (list?) of all the files (which happen to be image files).
-creates a new folder inside the base folder and calls it imagesX where X increases by one every time the script is run
-moves all the files into the images folder
-within the base folder it creates a new text file and calls it imagesX.js
-writes a "//-" into imagesX.js
-then writes the list of filenames into the imagesX.js twice, separated by an empty line, and adds a semicolon to the end of each filename and saves imagesX.js
-from a folder a level above the base folder it copies a file called index.html into the base folder and renames in indexX.html
-in indexX.html it replaces a string "replaceThis" with "imagesX.js"
The task is more complex but this would help me tremendously do the rest.
If I am asking for too much on this forum please let me knowThis should get you started.
The description of how you want to write the data isn't clear, but the rest should work (untested):
property imageNum : 0 -- last used ImageNumber
-- within a base folder it takes an inventory (list?) of all the files (which happen to be image files).
-- get the folder:
set baseFolder to (choose folder)
-- now get the files within it:
tell application "Finder"
set fileList to every file of folder baseFolder as alias list
end tell
--creates a new folder inside the base folder and calls it imagesX where X increases by one every time the script is run
tell application "Finder"
set imageNum to imageNum + 1
set newImageFolder to make new folder at baseFolder with properties {name:"images" & imageNum}
-- moves all the files into the images folder
move every file of folder baseFolder to newImageFolder
--within the base folder it creates a new text file and calls it imagesX.js
set textFile to (open for access file (baseFolder as text) & "images" & imageNum & ".js" with write permission)
--writes a "//-" into imagesX.js
write "//-" to textFile
-- then writes the list of filenames into the imagesX.js twice, separated by an empty line, and adds a semicolon to the end of each filename and saves imagesX.js
-- need more info here
-- a blank line between each instance of the file name? or all file names, blank line, all file names again?
-- an example, please
close access textFile
--from a folder a level above the base folder it copies a file called index.html into the base folder
--and renames in indexX.html
--in indexX.html it replaces a string "replaceThis" with "imagesX.js"
-- the easiest way of doing this is to read the file and write a new copy with the changes - that's easier than changing it in situ:
set indexHTML to (read file "index.html" of folder (container of baseFolder))
set {oldTIDs, my text item delimiters} to {my text item delimiters, "replaceThis"}
set indexHTML to text items of indexHTML
set my text item delimiters to "imagesX.js"
set indexHTML to indexHTML as text
set my text item delimiters to oldTIDs
set indexFile to (open for access file ("index" & imageNum & ".html") with write permission)
write indexHTML to indexFile
close access indexFile
end tell -
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 -
NEED HELP IN MATRIX WITH GROUP REPORT
Dear All,
I need small help in MATRIX WITH GROUP REPORT In Report Builder Test Report
In my report, having periods as rows and location as columns as shown below,
1) LOC-A
JAN-10 FEB-10
ITEM-GROUP -1 1 2
ITEM-GROUP-2 3 4
ITEM-GROUP 3 5 6
2) LOC- B
MAR-10 APR-10
ITEM-GROUP -1 7 8
ITEM-GROUP-2 9 10
ITEM-GROUP-3 11 12
But comming to my requirement, the periods should be in fix in matrix as shown below
1) JAN-10 FEB-10 MAR-10 APR-10
LOC-A
ITEM-GROUP -1 1 2
ITEM-GROUP-2 3 4
ITEM-GROUP 3 5 6
LOC- B
ITEM-GROUP -1 0 0 7 8
ITEM-GROUP-2 0 0 9 10
ITEM-GROUP-3 0 0 11 12
I am unable to get this kind of output format
Please kindly waiting for reply from our team....
Regards
krishna.PFor the periods, create a seperate dummy query and then use it as column group in the multi query matrix.
-
Is any one tell me that JAVA BEAN only used in WEB or also you in Desktop applications???? and aslo tell how i implement Java class and use JAVA BEAN. I need help regarding above matter
thanks in advance
Rehan MIrzaHere is a good link that indicate that JavaBean is not only for applets
http://java.sun.com/docs/books/tutorial/javabeans/whatis/beanDefinition.html
quote:
The JavaBeans API makes it possible to write component software in the Java programming language. Components are self-contained, reusable software units that can be visually composed into composite components, applets, applications, and servlets using visual application builder tools. JavaBean components are known as Beans.
Francois -
Need help Pagination Suppourt with DataGrid
Hi ,
When i do a search Operation , the data from Database is huge and i think if i display all of them at a Time it will be a performance and response Time issue .
So the question i am asking is that , can any body please give me a basic idea as how to implement Pagination with DataGrid Results ??
Need help with Datgrid and Pagination suppourt .
Thnaks in advnace .Hi Kiran,
Try referring to the below link...
http://www.flexicious.com/
Thanks,
Bhasker Chari.S -
Replaced hard drive in compaq presario cq62, need help recovering it with out disks
Recently replaced the hard drive in my notebook due to failure of original. Need help recovering it without disks
If you are wanting to install the original copy of Windows it came with, you will need a set of recovery disks.
Otherwise, you can purchase a copy of Windows to install and download the appropriate drivers from http://goo.gl/hOm3. Just make sure the copy of Windows that is installed is at least the same family of Windows to ensure that drivers are available.
What is the exact model of the notebook and product number?
NOTE: Do not provide the serial number.
↙-----------How do I give Kudos?| How do I mark a post as Solved? ----------------↓
Maybe you are looking for
-
How TDS Reverse at the time of Down Payment Clearing F54
Dear Friends, Please let me know what is the process or configuration we have to do for clear TDS in F-54. my scenario is I made down payment of Rs. 10000/- with TDS. next we are doing MIRO for Rs. 50000/- with TDS full amount Then I m adjusting down
-
Export to PDF causes blacks to go grey.
Hello, I have been dealing with an issue involving the way InDesign exports to PDF. In images and boxes drawn in InDesign the black value is being reduced to 95% while the text remains full black. I thought it was a printer issue but I looked more
-
Sync new Apple ID pruchases with old Apple ID
I created a new Apple ID (that was the easy part), but now none of my thousands of purchases (Apps, Songs, Books, etc.) don't show under the new Apple ID. Is there was way to sync them?
-
Newer HP printers are being released as 10.5+ compatible. I can see the new .gz definitions in Snow Leopard (/Library/Printers/PPDs/Contents/Resources) after the latest Software Update via Apple. Can this file simply be copied into the appropriate f
-
Use of "overflow:auto" in a div vs a table
Pest is back. I am building pages where there are potentially VERY long tables, and I only want them to take up "X"px of vertical space. Using a <div> to surround the table, adjusting the height and width of the <div> to whatever I want has been VER