-
MySql help Request
Hi everyone,
I need some help using java and mysql. Has anyone heard and used MySql??
I have downloaded and installed the MySql server and created a small database file called t1 (just as a test file). It has one table in it. I have also downloaded a file from the MySql website call a MySql connector for Java. I extracted the files in the MySql directory. But I don't know what to do next. There is a file called MySql-connector-java-3.1.10-bin.jar.
How do I use the MySql server and it databases in a Java program? I have used a Microsoft Access database with a java program. I remember having to go to the windows ODBC Data Source Administrator and add a User DSN for the database file that I wanted to use. I tried doing that but unsuccessfully. MySql wasn't in the list to choose from.
I really need help here. I posted messages at the MySql site but no one has replied.
Richard
-
Can't really help you with Java, but did you happen to take a look at the documentation?
http://dev.mysql.com/doc/mysql/en/java-connector.html
Paul
~~~~
Microsoft MVP (Visual Basic)
-
Thanks
Thanks for your reply but do you know where to set tht CLASSPATH so that I can have access to the driver from any directory.
-
copy that .jar file in to ur jre and paste it inside
/jre<version>/lib/ext/
after this u can access the database using jdbc
-
Thanks
Thanks for your help but i am still doing something wrong here. I did what you said to do but it still doesn't work. I get a runtime error SQL Error: java.sql.SQLException: No suitable driver 0 08001
Here is the code I am running:
import java.sql.*;
public class mysqldatabasetest1 {
public static void main(String[] arguments) {
String data = "jdbc:mysql:t1";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
data, "", "");
Statement st = conn.createStatement();
ResultSet rec = st.executeQuery(
"SELECT * " +
"FROM male ");
while(rec.next()) {
int n = 1;
System.out.println(rec.getString(++n) + "\t"
+ rec.getString(++n) + "\t"
+ rec.getString(++n));
}
st.close();
} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception e) {
System.out.println(" Error: " + e.toString()
+ e.getMessage());
}
}
}
Something is still wrong. Please go through the code.
Thanks
-
String data = "jdbc:mysql://<ip address >:<port no>t1";
ip address-the ip address of the machine where u hve ur database if u are in a network
port no-the port no in which mysql is running--if u hvnt assigned any port no
the default no will be-3306
if u r not in a network
the try using
String data = "jdbc:mysql://localhost:3306/t1";
-----------------------------------------------
now the second thing is
Connection conn = DriverManager.getConnection(
data, "<your my sql userid>", "<password>");
if u r loging in the database as administrator
then
Connection conn = DriverManager.getConnection(
data, "root", "<password>");
try this .....sometimes this will solve the problem
------------------------------------------------
vsorc-
-
finally working
I un-installed all of my java components, deleted all of the java directories and then downloaded and installed the latest jdk 5. Then I followed what vsorc suggested to do and it worked. Thanks vsorc for your help. I am using a gui windows application to write my java code (JCreator) and it is working fine now.
Now I just have to be able to make it work from the command line. I am having troubles I think I need to set the path to the java and javac executables because I can't use them from the current directory where the program resides. How do you do this? I thought I knew how but I guess not.
Similar Threads
-
Replies: 0
Last Post: 05-26-2005, 04:10 AM
-
By felix in forum ASP.NET
Replies: 2
Last Post: 04-05-2002, 05:01 AM
-
By Michael Welch in forum .NET
Replies: 0
Last Post: 02-26-2002, 10:17 AM
-
By John Wood in forum Architecture and Design
Replies: 1
Last Post: 07-02-2001, 06:24 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks