I write simple program to connect with database, execute simple query and
print. My driver to MySql work good coz program :
public class test {
public static void main(String[] args) {
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance);
System.out.println("Good to go");
}
catch (Exception E) {
System.out.println("JDBC Driver error");
}
}
}
print, "Good to go", but when i try sth like this :
connection = DriverManager.getConnection(
"jdbc:mysql://{numbers and dot's}", "JarekB?aszczyk" , "151083");
and i have exception :
SQLException: No suitable driver
SQLState: 08001
VendorError: 0
java.lang.NullPointerException
at Hello.executeSQL(Hello.java:55)
at Hello.main(Hello.java:80)
Exception in thread "main"
I no neeed to write localhost coz when i connected to that base in Php i
write the same numbers.
How can i connect to that base ???
What i do wrong??
--
Tasiek
Dieter Bender - 01 Oct 2004 11:43 GMT
Hi,
your Database name in the url is missing
try somethin like that:
> connection = DriverManager.getConnection(
> "jdbc:mysql://{numbers and dot's}", "JarekB³aszczyk" , "151083");
connection = DriverManager.getConnection(
"jdbc:mysql://{numbers and dot's}/DBName", "JarekB³aszczyk" , "151083");
and put in the name of your database for DBName
Dieter
Tasiek - 03 Oct 2004 21:23 GMT
> and put in the name of your database for DBName
I tried this befor and nothing better :/
--
Tasiek
_Mario_ - 01 Oct 2004 12:02 GMT
>I write simple program to connect with database, execute simple query and
> print. My driver to MySql work good coz program :
[cut]
> I no neeed to write localhost coz when i connected to that base in Php i
> write the same numbers.
> How can i connect to that base ???
> What i do wrong??
Google and his examples ;)
public class TestQuery {
public TestQuery () {
}
public static void main(String args[]) {
String url="jdbc:mysql:///therocks";
Connection con;
String query = "SELECT * FROM addressbook";
Statement stmt;
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
System.out.println("Trying to connect...");
con = DriverManager.getConnection (url, "root", "password");
System.out.println("connected!");
stmt = con.createStatement();
ResultSet result = stmt.executeQuery(query);
while (result.next()) {
String name = result.getString(1) + " " +
result.getString(2);
System.out.println(name);
}
stmt.close();
con.close();
System.out.println("End test");
}
catch(SQLException ex) {
System.err.print("SQLException: ");
System.err.println(ex.getMessage());
}
}
}
This works correctly...
Mario
Tasiek - 03 Oct 2004 21:28 GMT
> This works correctly...
This program in my comp (i use eclipse) throw
java.net.ConnectException. So ... i have wrong Driver to MySql or in wrong
place?
--
Tasiek