Set a classpath for mysql and java connectivity

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swethak
    New Member
    • May 2008
    • 118

    Set a classpath for mysql and java connectivity

    hi,

    when i run a java program for to store data and retrive using mysql datatabse i got the following errors.I think in that one of error is due to set the class path.I placed my mysql-connector-java-3.0.11-stable-bin jar in lib directory.What is the command to set a classpath in windows for java mysql connectivity.pl z tell that .And also how i avoid these errors.

    [java]
    import java.sql.*;
    import java.util.*;
    import java.net.*;
    import java.io.*;
    import java.sql.Connec tion;
    import java.sql.Driver Manager;
    import java.sql.SQLExc eption;
    import java.sql.*;
    class Test
    {
    public static void main(String args[])
    {
    Class.forName(" org.gjt.mm.mysq l.Driver").newI nstance();
    //dbCon = DriverManager.g etConnection("j dbc:mysql://194.230.33.43/databasename", "phoneliv_root" , "root");
    dbCon = DriverManager.g etConnection("j dbc:mysql://localhost:3306/DataMiningdb"," root","root");
    Connection dbCon;
    ResultSet rsGroups;
    Statement stmtSql;
    String strSql="", strToMobileNo = "", strMemberName = "", groupId = "";

    /*
    ** The Statement enables the resultset obtained from it to be scrollable and read only.
    */
    stmtSql = dbCon.createSta tement(ResultSe t.TYPE_SCROLL_I NSENSITIVE, ResultSet.CONCU R_READ_ONLY);
    /*
    ** The List of the groups are retrieved and displayed.
    */
    stmtSql = dbCon.createSta tement(ResultSe t.TYPE_SCROLL_I NSENSITIVE, ResultSet.CONCU R_READ_ONLY);
    strSql = "Select * from vehicles";
    rsGroups = stmtSql.execute Query(strSql);
    while(rsGroups. next()){
    strMemberName = rsGroups.getInt ("vehicle_id ");
    strToMobileNo = rsGroups.getStr ing("vehicle_st ockno");
    groupId = rsGroups.getStr ing("vehicle_ma ke");
    }
    System.out.prin tln("strToMobil eNo");
    System.out.prin tln("strMemberN ame");
    System.out.prin tln("groupId");
    }
    }
    [/java]

    errors :

    C:\j2sdk1.4.0\b in>javac dbcon.java
    dbcon.java:15: cannot resolve symbol
    symbol : variable dbCon
    location: class Test
    dbCon = DriverManager.g etConnection("j dbc:mysql://localhost:3306/DataMiningdb"," root
    ","root");
    ^
    dbcon.java:32: incompatible types
    found : int
    required: java.lang.Strin g
    strMemberName = rsGroups.getInt ("vehicle_id ");
    ^
    2 errors

    plz help me.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    It has nothing to do with classpaths (yet), you forgot to define your identifier dbCon
    as a Connection. The other error is just silly: i,e. you retrieve an int from your
    result set and want to assign it to a String.

    kind regards,

    Jos

    Comment

    Working...