Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / October 2004

Tip: Looking for answers? Try searching our database.

[MySql] Connecion .... dont work :/

Thread view: 
Tasiek - 01 Oct 2004 11:11 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.