Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-04-2008, 06:22 AM   PM User | #1
swethak
New Coder

 
Join Date: Jul 2008
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
swethak is an unknown quantity at this point
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.plz tell that .And also how i avoid these errors.

Code:
import java.sql.*;
import java.util.*;
import java.net.*;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
class Test
{
public static void main(String args[])
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
//dbCon = DriverManager.getConnection("jdbc:mysql://194.230.33.43/databasename", "phoneliv_root", "root");
dbCon = DriverManager.getConnection("jdbc: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.createStatement(ResultSet.TYPE_SCROLL_INSENS ITIVE, ResultSet.CONCUR_READ_ONLY);
/*
** The List of the groups are retrieved and displayed.
*/
stmtSql = dbCon.createStatement(ResultSet.TYPE_SCROLL_INSENS ITIVE, ResultSet.CONCUR_READ_ONLY);
strSql = "Select * from vehicles";
rsGroups = stmtSql.executeQuery(strSql);
while(rsGroups.next()){
strMemberName = rsGroups.getInt("vehicle_id");
strToMobileNo = rsGroups.getString("vehicle_stockno");
groupId = rsGroups.getString("vehicle_make");
}
System.out.println("strToMobileNo");
System.out.println("strMemberName");
System.out.println("groupId");
}
}
errors :

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

plz help me.

Last edited by Aradon; 08-04-2008 at 10:40 AM..
swethak is offline   Reply With Quote
Old 08-04-2008, 07:59 AM   PM User | #2
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
see this howto to configure java installation on windows
http://www.cs.ucsb.edu/~teliot/Path_and_Classpath.htm

and this guide (at the bottom) for mysql etc
http://eil.stanford.edu/neesgrid/dat...src/README.txt

cheers
~E

Last edited by ess; 08-04-2008 at 08:01 AM..
ess is offline   Reply With Quote
Old 08-16-2008, 06:05 PM   PM User | #3
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
Quote:
Originally Posted by swethak View Post
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.plz tell that .And also how i avoid these errors.
from your example you haven't actually run ur program...u have just compiled it. heres how you set the classpath in windows...
Code:
set CLASSPATH=%CLASSPATH%;c:\my-app\lib\driver.jar;
or you could also add an entry in the My Computer->properties->advanced->environment variables

Quote:
Originally Posted by swethak View Post
Code:
import java.sql.*;
import java.util.*;
import java.net.*;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
class Test
{
public static void main(String args[])
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
//dbCon = DriverManager.getConnection("jdbc:mysql://194.230.33.43/databasename", "phoneliv_root", "root");
dbCon = DriverManager.getConnection("jdbc: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.createStatement(ResultSet.TYPE_SCROLL_INSENS ITIVE, ResultSet.CONCUR_READ_ONLY);
/*
** The List of the groups are retrieved and displayed.
*/
stmtSql = dbCon.createStatement(ResultSet.TYPE_SCROLL_INSENS ITIVE, ResultSet.CONCUR_READ_ONLY);
strSql = "Select * from vehicles";
rsGroups = stmtSql.executeQuery(strSql);
while(rsGroups.next()){
strMemberName = rsGroups.getInt("vehicle_id");
strToMobileNo = rsGroups.getString("vehicle_stockno");
groupId = rsGroups.getString("vehicle_make");
}
System.out.println("strToMobileNo");
System.out.println("strMemberName");
System.out.println("groupId");
}
}

Quote:
Originally Posted by swethak View Post
C:\j2sdk1.4.0\bin>javac dbcon.java
dbcon.java:15: cannot resolve symbol
symbol : variable dbCon
location: class Test
dbCon = DriverManager.getConnection("jdbc:mysql://localhost:3306/DataMiningdb","root
","root");
^
you are using dbConn before even declaring it...see above the code highlighted in red

Quote:
Originally Posted by swethak View Post
dbcon.java:32: incompatible types
found : int
required: java.lang.String
strMemberName = rsGroups.getInt("vehicle_id");
^
2 errors
here again you are trying to assign an int to a string variable...

if you had just read the errors thrown by the compiler you could have solved these problems, please find a good java tutorial and learn
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
shyam is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:24 AM.


Advertisement
Log in to turn off these ads.