473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Set a classpath for mysql and java connectivity

118 100+
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.

[java]
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").newInstan ce();
//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");
}
}
[/java]

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.
Aug 4 '08 #1
1 2460
JosAH
11,448 Expert 8TB
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
Aug 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Herman | last post by:
Hi everyone, I recently installed the Sun J2SE SDK on my machine, and I am having trouble running the java.exe interpreter for my Java compiled code. I remember that I had to set my environment...
2
by: David Cook | last post by:
Windows (XP and NT) allows one to specify environmental variable (such as PATH and CLASSPATH) at both the SYSTEM-wide level as well as at the per-USER level. And the behavior has always been...
4
by: Abdelhalim MIMOUNI | last post by:
hi, i'm new to java, and using sun last JDK, and i'm trying to understand how work this feature when we want to compile at command line ? i'm trying to set the classpath to the directory of the...
7
by: dlarsson | last post by:
Okay folks, I thought I was doing something very, very simple, but I cannot seem to get this to work at all. Can anyone identify what I am doing wrong here-? _________________________________ ...
9
by: KevinRobinson | last post by:
Hi, Can anyone please tell me how to add or change a Java classpath in SUSE Linux 9.3. I have set up a Tomcat server but my Java Classes will not run although they do on a windows box. ...
10
rhitam30111985
by: rhitam30111985 | last post by:
hi all .. java/jdbc newbie here ... i cant seem to perform the most basic step for database connectivity using java . here is my code : import java.sql.*; public class connect { ...
0
by: MIRRA | last post by:
Hi I have a UNIX script which creates a report. In that script I have to define the java classpath. Also I need to check if the java classpath specified exists or not. Below is the command i use ...
0
madhoriya22
by: madhoriya22 | last post by:
Hi, I am setting class path for the Axis webservices framework.This is how I have set the paths : AXIS_HOME : C:\axis AXIS_LIB : %AXIS_HOME%\lib AXISCLASSPATH :...
1
Ganon11
by: Ganon11 | last post by:
Hey all, I'm setting up my computer to run Java for a class I'm taking, and I've gotten into a bit of a snag. I've set the CLASSPATH system variable to include the base folder of my homeworks...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.