aspose file tools*
The moose likes JDBC and the fly likes Linux mysql and Jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Linux mysql and Jdbc" Watch "Linux mysql and Jdbc" New topic
Author

Linux mysql and Jdbc

Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 87
i fisrt in the linux box type these command
#CLASSPATH=.:/usr/java/mysqldriver/mysql-connector-java-3.0.11-stable/mysql-connector-java-3.0.11-stable-bin.jar
#export CLASSPATH
i can run my helloworl.java program but when i try work with java and mysql in linux i get these error: "java.sql.SQLException: Driver not found for URL: jdbc:mysql://localhost:3306/listas/" (the databases listas exist!!) any advice?
(javac OK but java jdbc1 not)

import java.sql.*;
import java.util.*;
import java.io.*;
import com.mysql.jdbc.Driver;
import java.util.Timer;

public class jdbc1
{
public static void main (String arg[])
{
try {
// new Driver();
Class.forName("com.mysql.jdbc.Driver");
Properties props = new Properties();
props.setProperty("user","root");
props.setProperty("password","123456");
// props.setProperty("password","123456");
//Table[] cells = new Table[colNames.length];
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/listas/", props);
Statement stmt = con.createStatement();
String query = "SELECT * FROM tdatgen where cdatgenclave like 'ACOACO%'";
ResultSet answer = stmt.executeQuery(query);
ResultSetMetaData meta = answer.getMetaData();
int colCount= meta.getColumnCount();
while (answer.next())
{
for (int col=1;col<colCount;col++)
{
System.out.print(answer.getString(col) +"\n");
try
{
Thread.sleep(4000);
}
catch (Exception ee){}
//cells[col].add(cell);
}
}
} catch (Exception Ex) {
System.out.println(Ex.toString());
}
}
}

Thanks
Jason Steele
Ranch Hand

Joined: Apr 25, 2003
Posts: 100

"java.sql.SQLException: Driver not found for URL: jdbc:mysql://localhost:3306/listas/" (the databases listas exist!!)

This error means that your url is not formed in a manner that coincides with a registered driver.
the url for mysql should look like this:

I think your error is with your trailing "/" after listas. Try removing it.


An egg is a chicken's house!
wayne hitchcock
Greenhorn

Joined: Dec 22, 2003
Posts: 8
I believe Jason's answer to be correct. I always include the user name & password within the url
private String url =
"jdbc:mysql://localhost:3306/machine_info?user=mm_webapp&password=zero31russell";
Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 87
i continue with my error:
"java.sql.SQLException: Driver not found for URL: jdbc:mysql://localhost:3306/listas/"
i modified my program:
import java.sql.*;
import java.util.*;
import java.io.*;
import com.mysql.jdbc.Driver;
import java.util.Timer;
public class jdbc2
{
public static void main (String arg[])
{
try {
// new Driver();
Class.forName("com.mysql.jdbc.Driver").newInstance();
String User="root";
String Password="linuxx";
String Url="localhost/listas";
String Res="jdbc:mysql://"+Url+"?user="+User+"&password="+Password;
try
{
Connection dbcon;
dbcon=DriverManager.getConnection(Res);
Statement stmt = dbcon.createStatement();
String query = "SELECT * FROM tdatgen where cdatgenclave like 'ACOACO%'";
ResultSet resp = stmt.executeQuery(query);
ResultSetMetaData meta = resp.getMetaData();
int colCount= meta.getColumnCount();
while (resp.next())
{
for (int col=1;col<colCount;col++)
{
System.out.print(resp.getString(col) +"\n");
try
{
Thread.sleep(4000);
}
catch (Exception ee){}
//cells[col].add(cell);
}
}
} catch (SQLException ex)
{
while (ex != null)
{
System.out.println("SQL:"+ex.getMessage());
ex=ex.getNextException();
}
}
} catch (Exception Ex) {
System.out.println(Ex.toString());
}
}
}
much thanks for yours times.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Linux mysql and Jdbc
 
Similar Threads
websphere studio and mysql
Help: Connecting MySQL Database to JTable
java/MYSQL Serious speed problem.
Strange JDBC-MySQL connection error
not able to connect to the database