Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003

    JDBC & MySQL problems

    Hi guys,
    I am a newbie in Java &amp; SQL. I am currently working on a WAP project using JSP &amp; MySQL as the DBMS. My questions:

    1. Java compiler: I saw in the manual we can use javac -sourcepath &lt;dir&gt; &lt;file&gt;. But when i tried to do that, it generates errors that says &quot;Error: cannot read: filename.java&quot;. It works only when i place the .java file in the bin directory of the JDK and compile it with javac filename.java, it works! What is the problem? It is a real hassle everytime i need to copy those servlets to JDK bin's directory, compile and copy back to my development directory. For your information my JDK dir is in d:/fyp/JDK1.3.1 and my Tomcat development dir is in d:/fyp/Tomcat/webapps/Root/WEB-INF/classes. Can someone also explain what's the difference wbetween javac -sourcepath, javac -classpath and javac -d &lt;dir&gt;?

    2. JDBC.
    I am using mysql jdbc driver called 'org.gjt.mm.mysql.Driver' where it's .jar file was placed in the 'lib' directory in Tomcat. Please tell me if im correct. What is the easiest way to test that my JDBC driver works? How can I test it with a database that I have created in 'd:/mysql/data/projectdb' with the JDBC driver in Tomcat since BOTH of them are in different directories (JDBC in d:/fyp/Tomcat &amp; MYSQL is in d:/mysql)?

    3. Web.xml
    do i need to tweak the VALUES in the lines in web.xml to make sure that my JDBC driver works?

    Please advice how can i make this -&gt; jdbc:mysql://localhost/projectdb possible since Tomcat &amp; MySQL is both in different directories?

    Please help. I'm stuck.

  2. #2
    Registered User
    Join Date
    Mar 2003

    RE: JDBC & MySQL problems


    1. '-sourcepath', '-classpath' and '-d' are all explained in the help of javac (javac -help). Of course knowing what they are is not the same as knowing how to use them. I wish all -help included simple examples. I had to learn it the hard way, so here is an example for you:

    javac -classpath &quot;path_to_tomcat\common\lib\servlet.jar&quot; -sourcepath &quot;path\to\servlets\src\&quot; -d &quot;path_to_tomcat\webapps\yourapp\WEB-INF\classes&quot; *.java

    Getting the syntax right is important... i.e. '\' for windows or '/' for linux. The double quotes proved necessary in my case, and even the trailing '\' in the sourcepath (wouldn't work without it).

    2. Isn't that driver written by the guy now working for MySQL? If so then it's been discontinued. You should use the renamed Connector/J (http://www.mysql.com/products/connector-j/index.html). All the instructions are in the distribution zip. The jar should be in the common/lib indeed (along with all the other jars).

    3. I never needed to change or add anything to web.xml. In my case all the info needed is hard-coded in the source (nobody's perfect). Example:

    java.sql.Connection conn;
    String myQuery = &quot;SELECT * FROM mytable;&quot;;


    conn = DriverManager.getConnection(&quot;jdbc:mysql://localhost/myDB?user=johnsmith&amp;password=johnspass&quot;

    Statement st = this.conn.createStatement();
    ResultSet rs = st.executeQuery(myQuery);

    // rs should now include your results
    // do whatever you want with them, like loop and print
    System.out.print(&quot;[&quot;+rs.getString(&quot;column1&quot+&quot;] &quot;
    // etc...
    catch (Exception e) { System.err.println(e); }

    Hope this helps...



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts