Accessing MySQL on NetBeans using JDBC, Part II: Perform SQL Operations
Java, NetBeans January 16th, 2008From Part I, I have only established a connection with local MySQL. Next I’ll show how to retrieve and modify data on remote MySQL.
MySQL Connection using in this part
Suppose that I have MySQL running remotely on IP:192.168.1.101 with default port (3306) and I want to connect to Northwind database with username is ‘root’ and password is ‘123456’. The connection string will be
String connectionUrl = "jdbc:mysql://192.168.1.101:3306/Northwind?" + "user=root&password=123456";
Retrieve data from a database
To get some data, I need to execute query on the MySQL and get the result back to me. First, I create stmt (Statement object) and execute query in SQL language. Then I store the result on ResultSet object and iterative show the result on the output window.
Statement stmt = null; ResultSet rs = null; //SQL query command String SQL = "SELECT * FROM Products"; stmt = con.createStatement(); rs = stmt.executeQuery(SQL); while (rs.next()) { System.out.println(rs.getString("ProductName") + " : " + rs.getString("UnitPrice")); }
Code Explanation:
- Statement objects allow you to execute basic SQL queries and retrieve the results through the ResultSet class.
- In while-loop, iterative in the ResultSet object to show result in console (ProductName and UnitPrice columns in Products table) on output window.
The example result will be similar to below.
Note: I have imported only 4 records from Products table in Northwind database.

Update data on database
To insert, update and delete records on SQL Server, you can use the code from retrieve data from database and simply change SQL command and also modify some code a little bit. On update, I must use executeUpdate(�?SQL�?) method on statement object instead executeQuery(“SQL�?) and the return value will be rows affected instead of a record set.
Example
INSERT command
// SQL insert command String strSQL = "INSERT INTO Products (ProductName,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder," + "ReOrderLevel,Discontinued) VALUES ('MyProduct','10 Kg.',1234.0000,100,50,30,0)"; int rowsEffected = stmt.executeUpdate(strSQL); System.out.println(rowsEffected + " rows effected");
UPDATE command
// SQL update command String strSQL = "UPDATE Products SET UnitPrice = 900, UnitsInStock = 55, UnitsOnOrder = 5 WHERE ProductName = 'MyProduct'"; int rowsEffected = stmt.executeUpdate(strSQL); System.out.println(rowsEffected + " rows effected");
DELETE command
// SQL delete command String strSQL = "DELETE FROM Products WHERE ProductName = 'MyProduct'"); int rowsEffected = stmt.executeUpdate(strSQL); System.out.println(rowsEffected + " rows effected");
Summary
You can download source code example testMySQL.java (Right-click on the link and select Save target As…).
But you have to change connection string to match your environment. The example code will connect to Northwind database and try to retrieve records, insert a new record, update the record and delete the record from Products table. The result is below.

Related post
- Accessing SQL Server on NetBeans using JDBC, Part II: Perform SQL Operations From Part I, I have only established a connection with local SQL Server. Next I’ll show how to retrieve and...
- Accessing MS Access 2007 on NetBeans 6.5 using JDBC, Part 4: Perform SQL Operations This article is one of the series of Accessing Access 2007 on NetBeans 6.5 using JDBC. You can see the...
- Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations Perform SQL Operations From the previous part, I have successfully connect to world database on MySQL Server from VB.NET. Next,...
- Accessing MySQL on NetBeans using JDBC, Part I: Create a connection Introduction This tutorial show you how to use NetBeans to connect MySQL by using MySQL Connector/J, MySQL AB’s JDBC Driver...
- Accessing SQL Server on NetBeans using JDBC, Part III: Troubleshooting This post is the last part which gathers common problems along with solutions about accessing SQL Server using JDBC on...
Related posts:




April 23rd, 2008 at 10:24 am
Thanks a lot! That is exactly what I needed to get jump-started on Java & MySQL.
June 3rd, 2008 at 6:57 am
Very good.
You have no idea how hard it is to find a simple explanation like this.
June 11th, 2008 at 11:00 pm
can i ask u question
why i cannot build because of the con.
The result of the compiler is above
symbol : variable con
location: class test.test
stmt = con.createStatement();
1 error
BUILD FAILED (total time: 0 seconds)
who can help me !?
June 12th, 2008 at 8:46 am
I think that you haven’t completed part1: create a connection yet. You need to create a connection to MySQL before performing any query. Try to read part1 first.
June 15th, 2008 at 9:07 pm
Thanks a lot. i had solved my problem
June 19th, 2008 at 3:32 am
Thank you for this tutorial. Very usefull indeed. I have a problem with this line:
stmt = con.createStatement();
when I write it in my Netbeans IDE, it gets red underlined, the error message says: “Cannot find symbol”
Any idea why?
NB: on the following line:
Connection con = DriverManager.getConnection(connectionUrl);
The line is underlined grey saying that the con variable is not being used. That might be the source of the problem…
I import the followings:
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
and use IDE 6.1 and MySQL 5.1, connector 5.1.6
June 20th, 2008 at 10:31 pm
Hi, Arnaud
Normally, when you see this error message, it’ll tell which symbol. For instance,
cannot find symbol
symbol : variable aaa
location: class Main
This means that you haven’t declare a variable ‘aaa’ before using it.
According to your problem, have you already declare all of variables? Try check stmt and connectionUrl. In my example above, I have declare stmt = null and connectionUrl = “jdbc:mysql…..”.
June 23rd, 2008 at 9:01 pm
@Arnaud: You have to put the code of this part inside the scope of the “try” command from Part I.
If you place the code outside, then the compiler doesn’t see the declaration for the Connection con.
June 24th, 2008 at 9:17 pm
Thanks Dory, that was the answer to my problem. As I said very new to java programming.
Sorry that was very basic.
Thank you both for your answers.
By the way anybody knows where I could find a tutorial to then bind this query (INNER JOIN through more than 1 table) to a JTable?
The NetBeans tutorials only shows how to bind a simple table to a JTable, which is not very usefull as most of my tables contains ID’s we are of no meaning to the interface use.
Thank you
July 18th, 2008 at 1:31 pm
It’s great!!! I was trying to find out a place to start JAVA MYSQL connection and found no where. All the writers assume that only professionals have the right to read their articles.
Thanks a lot for the simple but great and effective article.
October 9th, 2008 at 12:39 pm
thnks a lot
it worked for me
October 25th, 2008 at 7:59 am
Nice Job.
Obrigado!!!
October 28th, 2008 at 8:09 pm
How to insert, update and delete if we use has map method?
Can you explain about it???
October 28th, 2008 at 8:59 pm
Hi, inD_05
What do you means “map method”?
November 20th, 2008 at 5:48 am
Hi, I have followed your examples (parts I & II) and it compiles fine, BUT when invoking:
DriverManager.getConnection(url, user, pass);
it returns an error that i cant resolve by now:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
…
can you enlighten me here? THANKS!
November 20th, 2008 at 6:35 am
solved it
some how the “:port/” part of the conn string was causing troubles.
November 22nd, 2008 at 8:06 pm
Hi! Thanks for the great tutorial. All I need to know now is how I show the resultset on grid in Java using NetBeans
May 3rd, 2009 at 12:26 am
thanks so very mach:
muy buen tutorial.
great tutorial.
June 1st, 2009 at 7:22 pm
Cheers, Dude,
you’ve saved me loads of time!
All the best,
to
November 24th, 2009 at 9:44 am
thank’s a lot
the world needs people like you
It helps in a simple way
December 1st, 2009 at 6:20 am
Efectivamente,
muchas gracias por la demostración.
December 10th, 2009 at 11:50 am
Thanks a lot. the tutorials helped me to start my journey with Java. Expecting a lot from you genius
December 17th, 2009 at 8:20 pm
I have a table named “Ciudades” with the following structure:
cod_ciudad = int
nom_ciudad = varchar
cod_provincia = varchar
I want to retrieve data from the table with the following code but instead I get nothing.
(the connection has already been created and opened)
sSentencia = m_cConexion.createStatement();
rsResultado = sSentencia.executeQuery(“SELECT * FROM Ciudades ” +
“WHERE cod_ciudad >= ” + Integer.toString(iCodigoDesde) +
” AND cod_ciudad <= " + Integer.toString(iCodigoHasta));
What am I doing wrong?
Thanks in advance.
January 6th, 2010 at 10:42 am
Hi, Veronica
Is there any error message? First, you should try to test if the SQL query’s syntax is correct by print out the query to console window and copy it to run on the SQL Server.
February 25th, 2010 at 1:45 pm
I followed ur instruction step by step.. it successfully build but fail to run..
SQL Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure.
The last packet sent successfully to the server was 0ms ago. The driver has not received any packets from the server.
Why is this so? What should I check in this case?
Java Beginner
February 26th, 2010 at 10:06 am
Hi, Sitti
Check if the MySQL is accepting the connection from your application. Or if there is any firewall blocking.
February 26th, 2010 at 4:39 pm
Hi linglom,
Nothing change when I disable the firewall… How do i check for if MySQL is accepting the connection?? Is my connection string correct?? =)
try
{
Class.forName(“com.mysql.jdbc.Driver”);
String connectionUrl = “jdbc:mysql://localhost/Northwinds?;”;
Connection con = DriverManager.getConnection(connectionUrl);
}
catch (SQLException e)
{
System.out.println(“SQL Exception: “+ e.toString());
}
catch (ClassNotFoundException cE)
{
System.out.println(“Class Not Found Exception: “+ cE.toString());
}
March 2nd, 2010 at 9:07 am
Hi, Sitti
First, I thought that your MySQL is on remote machine. So if it on the local machine, I suggest you to change the connection string “localhost” to your real ip address of the machine.
Also, have you forgot username and password on the connection string?
March 3rd, 2010 at 9:57 pm
hey the records are getting inserted in table properly,but when i am trying to retrieve a single row i am getting a blank page. when i retrieve da whole table it is retrieving… but for one particular row it is not….
my query is : “select * from stu_detail where std_rollno=+ num +”
( String num=request.getParameter(“stdrollnumber”);
when i enter student roll number i am supposed to get student name,father’s name,address and contact no in the same page inside the textboxes.
March 4th, 2010 at 10:10 pm
Hi, Halima
I suggest you print out your query on output window and copy it to run on SQL Server directly to see if there is any error or not.
March 5th, 2010 at 2:05 pm
Thank linglom.. great help… I’m able to start working on it.. ♥
March 6th, 2010 at 9:07 pm
hey i tried in other system ,its working perfectly but i dont know wat’s da error….
plz help me with other query to retrieve a record , whatever user selects…
March 8th, 2010 at 5:37 pm
hey i retrieved all da records from the database in an table(i hav 5 columns i.e,- rollnumber,name,father’s name,address,ph).I have made da rollnumber as an link, so when i click on one particular rollnumber i should get all da columns of dat record in an table so dat i can edit and update it using servlet…
How to do it….???
March 23rd, 2010 at 1:14 am
Hello Friends Feels so good to be at a place of my interest where a hope that someone can help:
I am using netbeans for my project and mysql database to create a hash table for my web search engine project
the program runs fine the Problem: is Where does the actual physical data of the mysql table is stored.
I can locate the .frm files of the table but there needs to be an .Myd file also where does it get stored??
////////////please help anyone////////////
March 31st, 2010 at 3:36 pm
Linglom, you really did well with the way you explained this. I was able to even apply it to my JApplet in Netbeans and the part where I had to add MySQL Driver to the library made the difference.
I’d thought of using this information for my Java web development in Netbeans, but although the applet was running without any error, I kept getting a “ClassNotFoundException” error message.
What I did was to use the <jsp:plugin … to insert the applet
Please, give your counsel. Thank you.
March 31st, 2010 at 3:43 pm
…
Applet compiled and was executed without any error, but when I used the tag to insert it into the web page, a “ClassNotFoundException” error message was generated and the part where the statement:
==>Class.forName(“com.mysql.jdbc.Driver”);<==
was made never got executed.
—
Just explaining better… Thank you.
March 31st, 2010 at 4:02 pm
…
Wow! This is cool
April 15th, 2010 at 3:07 am
THnX a LOT MAn…..REalLY HelPFUl ……..
GOd BlESS YoU..
April 15th, 2010 at 3:07 am
THnX a LOT MAn…..REalLY HelPFUl ……..
May 27th, 2010 at 11:09 pm
great!
Thanks for the info.
It is simple and superb!
June 17th, 2010 at 3:20 pm
Thanks a lot for this. It was simple highly useful.
July 16th, 2010 at 7:14 pm
thank youuuuuuuuuuu….soooooooooooooo much…..there was great difficulty in update query…..you solved the problem…
September 10th, 2010 at 12:43 am
Just like all the previous Posts…THANK YOU!!! Took a lot of stress of my shoulders!!
November 23rd, 2010 at 10:44 am
I created a java desktop application that accept value for name,address and city and i have a button which will submit the information to the database, i need the code i will put in the action listener of the button that will submit all the data to mysql database
December 13th, 2010 at 8:05 pm
hi! can u send me a simple login program in jsp with mysql with validations and login failed msg if given wrong username and password.im able to establish a connection string but it goes to the next page even when i give wrong user name and password though i ve created a user table with username and password data. thank you !!!
January 7th, 2011 at 12:12 am
hey! i need to write a query to delete a record in the mysql table using java.
this is the command:
try{
Class.forName(“java.sql.Driver”);
Connection c=DriverManager.getConnection(“jdbc:mysql://localhost/hrishi”,”root”,”mysqldb”);
Statement s=c.createStatement();
ResultSet r=s.executeQuery(“delete from shop where num=18;”);
while(r.next()){
mnc.removeRow(mdl);
dlm1.remove(mdl);
}
c.close();
s.close();
r.close();
} catch(Exception e){
System.out.println(“Error”);
}
can u please tell me if theres an error or if there s somethin i need to add? Thank you.
January 7th, 2011 at 1:46 am
this tutorial is useful. thanks a lot.
February 4th, 2011 at 5:06 pm
Thankx
March 21st, 2011 at 1:42 pm
Thanks very much it has been very helpful for me… Love YOU!!!!
August 14th, 2011 at 12:18 pm
Thanks a lot
August 14th, 2011 at 12:27 pm
I had spend a lot of time for this purpose . But it help
me very much !!!!!!!!!!
August 20th, 2011 at 9:47 pm
nice explanations dude… if anyone has problems regarding basic SQL techniques, follow http://www.tharindu-rusira.blogspot.com
thank you
September 2nd, 2011 at 1:56 am
hey! i want to know the syntax if we have to retrive the data from table for a particular record. i m using netbeans for desktop app,in my app i entered value in field and after click on a button the required data is found. i m making app of employee record. means dat when i entered the emp_id then particular data of employee is found……….
“SELECT* From emp where id=…..”
what should i write in blank?
October 17th, 2011 at 10:29 am
Can anyone help me out by sending the query for an login form in mysql
November 18th, 2011 at 8:46 pm
can anyone help me out. i created a database on my system and accesd it with java but how can i transfer the database to another system and still access it …… it always gives me an error message
November 25th, 2011 at 12:32 am
I have read several just right stuff here. Definitely worth bookmarking for revisiting. I surprise how a lot effort you put to create the sort of excellent informative site.
December 25th, 2011 at 8:32 pm
Hello,
I want to add Search(mysql query) for a JButton and result should be shown in JTable . how can i do that ??? (I’m using NetBeans)
January 4th, 2012 at 4:02 pm
I have xampp mysql DB set on my pc. I want to perform ETL on a table from different machine. How can this be achieved ? Please put some light on this.
Thanks in advance.
January 9th, 2012 at 4:10 pm
My Source:
Imported:
import javax.swing.JOptionPane;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
code used for insertion:
try{
Class.forName(“java.sql.Driver”);
Connection con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/ebay”,”root”,”voxrazr”);
Statement stmt = con.createStatement();
String query = “INSERT INTO user_data VALUES (”
+fname.getText()
+”‘”+lname.getText()+”‘”
+”‘”+s_add.getText()+”‘”
+”‘”+city.getText()+”‘”
+”‘”+state.getText()+”‘”
+”‘”+pcode.getText()+”‘”
+”‘”+ptno.getText()+”‘”
+”‘”+email.getText()+”‘”
+”‘”+userid.getText()+”‘”
+”‘”+pass.getText()+”‘”
+”‘”+month.getSelectedItem()+”‘”
+”‘”+day.getSelectedItem()+”‘”
+”‘”+year.getSelectedItem()+”‘”
+”‘”+country.getSelectedItem()+”‘”+”);”;
ResultSet rs = stmt.executeUpdate(query);
}
catch(Exception e){
JOptionPane.showMessageDialog(null,”Error in connectivity”);
}
i got an error in:
ResultSet rs = stmt.executeUpdate(query);
output:
init:
deps-clean:
Updating property file: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\built-clean.properties
Deleting directory C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build
clean:
init:
deps-jar:
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build
Updating property file: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\built-jar.properties
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\classes
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\empty
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\generated-sources\ap-source-output
Compiling 1 source file to C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\classes
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3088: incompatible types
found : int
required: java.sql.ResultSet
ResultSet rs = stmt.executeUpdate(query);
1 error
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\nbproject\build-impl.xml:603: The following error occurred while executing this line:
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\nbproject\build-impl.xml:245: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 2 seconds)
Please help me to remove this error.
January 9th, 2012 at 5:41 pm
@Sahil:
ResultSet rs = stmt.executeUpdate(query);
Above code doesn’t return a ResultSet type but it returns an integer value as follows :
Return value:-
either the row count for SQL Data Manipulation Language (DML) statements or 0 for SQL statements that return nothing
So the code should be as follows : “stmt.executeUpdate(query); ” and not “ResultSet rs = stmt.executeUpdate(query); “
January 10th, 2012 at 5:31 pm
@ap:
The error is gone thanx for that. but still i didn’t get the desired result.Here i am showing you the code i used in MySQL:
CREATE DATABASE ebay;
USE eBay;
CREATE TABLE user_data
( fname CHAR(10),
lname CHAR(10),
strt_adrs VARCHAR(50),
city CHAR(15),
s_p_r CHAR(25),
pcode INTEGER,
pri_tele_no INTEGER,
eid VARCHAR(50),
userid VARCHAR(50),
password VARCHAR(50),
month CHAR(15),
day INTEGER,
year INTEGER );
ALTER TABLE user_data
ADD(country VARCHAR(20));
I wan’t to insert the data into it in a single click.
January 11th, 2012 at 2:12 pm
@Sahil : What error are you getting and on which line ?
January 11th, 2012 at 2:29 pm
The insert query should be somewhat like this..(i think), just try it out once :
“INSERT INTO user_data VALUES (”’
+fname.getText()+”’,'”
+lname.getText()+”’,'”
+s_add.getText()+”’,'”
+city.getText()+”’,'”
+state.getText()+”’,'”
+pcode.getText()+”’,'”
+ptno.getText()+”’,'”
+email.getText()+”’,'”
+userid.getText()+”’,'”
+pass.getText()+”’,'”
+month.getSelectedItem()+”’,'”
+day.getSelectedItem()+”’,'”
+year.getSelectedItem()+”’,'”
+country.getSelectedItem()+”’);”
January 12th, 2012 at 2:59 pm
Sorry about saying but when i put that my all code is showing error.
January 12th, 2012 at 3:37 pm
@Sahil :
Firstly, where are you writing this code, is it eclipse or netbeans or other.
and when you say u r getting errors do post the errors also.
January 13th, 2012 at 2:49 pm
NetBeans. And the following error i got when i used your code:
init:
deps-clean:
Updating property file: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\built-clean.properties
Deleting directory C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build
clean:
init:
deps-jar:
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build
Updating property file: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\built-jar.properties
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\classes
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\empty
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\generated-sources\ap-source-output
Compiling 1 source file to C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\build\classes
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3073: illegal character: \8220
String query = “INSERT INTO user_data VALUES (”’
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3073: ‘;’ expected
String query = “INSERT INTO user_data VALUES (”’
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3073: ‘;’ expected
String query = “INSERT INTO user_data VALUES (”’
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3073: illegal character: \8221
String query = “INSERT INTO user_data VALUES (”’
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3073: illegal character: \8217
String query = “INSERT INTO user_data VALUES (”’
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3074: illegal character: \8221
+fname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3074: not a statement
+fname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3074: illegal character: \8217
+fname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3074: ‘;’ expected
+fname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3074: unclosed character literal
+fname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3075: illegal character: \8221
+lname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3075: not a statement
+lname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3075: illegal character: \8217
+lname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3075: ‘;’ expected
+lname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3075: unclosed character literal
+lname.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3076: illegal character: \8221
+s_add.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3076: not a statement
+s_add.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3076: illegal character: \8217
+s_add.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3076: ‘;’ expected
+s_add.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3076: unclosed character literal
+s_add.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3077: illegal character: \8221
+city.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3077: not a statement
+city.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3077: illegal character: \8217
+city.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3077: ‘;’ expected
+city.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3077: unclosed character literal
+city.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3078: illegal character: \8221
+state.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3078: not a statement
+state.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3078: illegal character: \8217
+state.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3078: ‘;’ expected
+state.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3078: unclosed character literal
+state.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3079: illegal character: \8221
+pcode.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3079: not a statement
+pcode.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3079: illegal character: \8217
+pcode.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3079: ‘;’ expected
+pcode.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3079: unclosed character literal
+pcode.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3080: illegal character: \8221
+ptno.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3080: not a statement
+ptno.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3080: illegal character: \8217
+ptno.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3080: ‘;’ expected
+ptno.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3080: unclosed character literal
+ptno.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3081: illegal character: \8221
+email.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3081: not a statement
+email.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3081: illegal character: \8217
+email.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3081: ‘;’ expected
+email.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3081: unclosed character literal
+email.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3082: illegal character: \8221
+userid.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3082: not a statement
+userid.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3082: illegal character: \8217
+userid.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3082: ‘;’ expected
+userid.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3082: unclosed character literal
+userid.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3083: illegal character: \8221
+pass.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3083: not a statement
+pass.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3083: illegal character: \8217
+pass.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3083: ‘;’ expected
+pass.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3083: unclosed character literal
+pass.getText()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3084: illegal character: \8221
+month.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3084: not a statement
+month.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3084: illegal character: \8217
+month.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3084: ‘;’ expected
+month.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3084: unclosed character literal
+month.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3085: illegal character: \8221
+day.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3085: not a statement
+day.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3085: illegal character: \8217
+day.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3085: ‘;’ expected
+day.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3085: unclosed character literal
+day.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3086: illegal character: \8221
+year.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3086: not a statement
+year.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3086: illegal character: \8217
+year.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3086: ‘;’ expected
+year.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3086: unclosed character literal
+year.getSelectedItem()+”’,’”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3087: illegal character: \8221
+country.getSelectedItem()+”’);”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3087: not a statement
+country.getSelectedItem()+”’);”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3087: illegal character: \8217
+country.getSelectedItem()+”’);”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3087: ‘;’ expected
+country.getSelectedItem()+”’);”
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\src\ebay.java:3087: illegal character: \8221
+country.getSelectedItem()+”’);”
75 errors
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\nbproject\build-impl.xml:603: The following error occurred while executing this line:
C:\Users\VOXsaga\Documents\NetBeansProjects\ebay\nbproject\build-impl.xml:245: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 4 seconds)
January 13th, 2012 at 4:17 pm
@Sahil:
k…
First try adding a simple entry like this in Netbeans:
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,'XYZ’,'India’)”);
and let me know if this works…
Reply.
January 14th, 2012 at 3:25 pm
@ap:
For that i made a new database and a new project in netbeans.
Database code:
CREATE database Try;
USE Try;
CREATE TABLE user_data
(fname VARCHAR(20),
lname VARCHAR(20),
s_add VARCHAR(30));
NetBeans:
Project Name: try
Frame Name: try_1
+————+—————+—————-+
+ Control + Variable Name + Caption +
+————+—————+—————-+
+ Label + ————- + First Name +
+ Label + ————- + Last Name +
+ Label + ————- + Street Address +
+ Text Field + fn + ————– +
+ Text Field + ln + ————– +
+ Text Field + str_add + ————– +
+ Button + ————- + REGISTER +
+————+—————+—————-+
Source:
Import Commands:
import java.sql.*;
import javax.swing.JOptionPane;
Code:
try{
Class.forName(“java.sql.Driver”);
Connection con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/Try”,”root”,”voxrazr”);
Statement stmt = con.createStatement();
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
}
catch(Exception e){
JOptionPane.showMessageDialog(null,”Error in connectivity”);
}
Error:
init:
deps-clean:
Updating property file: C:\Users\VOXsaga\Documents\NetBeansProjects\try\build\built-clean.properties
Deleting directory C:\Users\VOXsaga\Documents\NetBeansProjects\try\build
clean:
init:
deps-jar:
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\try\build
Updating property file: C:\Users\VOXsaga\Documents\NetBeansProjects\try\build\built-jar.properties
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\try\build\classes
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\try\build\empty
Created dir: C:\Users\VOXsaga\Documents\NetBeansProjects\try\build\generated-sources\ap-source-output
Compiling 1 source file to C:\Users\VOXsaga\Documents\NetBeansProjects\try\build\classes
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: illegal character: \8220
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: ‘;’ expected
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: ‘;’ expected
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: not a statement
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: ‘;’ expected
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: not a statement
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: ‘;’ expected
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: not a statement
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: ‘;’ expected
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: illegal character: \8216
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: ‘;’ expected
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: illegal character: \8217
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: ‘;’ expected
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: unclosed character literal
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: illegal character: \8217
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: unclosed character literal
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: illegal character: \8217
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: not a statement
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
C:\Users\VOXsaga\Documents\NetBeansProjects\try\src\try_1.java:105: illegal character: \8221
statment.executeUpdate(“Insert into user_data(fname,lname,s_add) values(‘ABC’,’XYZ’,’India’)”);
19 errors
C:\Users\VOXsaga\Documents\NetBeansProjects\try\nbproject\build-impl.xml:603: The following error occurred while executing this line:
C:\Users\VOXsaga\Documents\NetBeansProjects\try\nbproject\build-impl.xml:245: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 1 second)
January 14th, 2012 at 3:32 pm
+————+—————–+————————-+—————-+
+ Control + Variable Name + Caption +
+————+—————–+————————-+—————-+
+ Label + ——————— + First Name +
+ Label + ——————— + Last Name +
+ Label + ——————— + Street Address +
+ Text Field + fn + ————–——— +
+ Text Field + ln + ————–——— +
+ Text Field + str_add + ————–——— +
+ Button + ——————— + REGISTER +
+——————–+————-————+———–—————+
January 16th, 2012 at 6:19 pm
@Sahil:
Just write a simple java program which shows entries from a table in DB without the GUI. And then include the code in GUI based program.
January 16th, 2012 at 6:24 pm
@sAHIL:
U can use this code to try out as said earlier.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class select {
public static void main(String args[]) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
Connection con=null;
Statement s=null;
ResultSet rs=null;
//DB connection
Class.forName(“com.mysql.jdbc.Driver”).newInstance();
con = DriverManager.getConnection(“jdbc:mysql://localhost/”,”root”,”");
System.out.println(“Connection Success!!”);
s = con.createStatement();
String query = “select * from “;
rs = s.executeQuery(query);
if(rs.next()) {
System.out.println(rs.getString(1) + “\t\t” + rs.getString(2));
}
}
}
January 16th, 2012 at 6:26 pm
@sAHIL:
iGNORE the earlier comment.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class select {
public static void main(String args[]) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
Connection con=null;
Statement s=null;
ResultSet rs=null;
//DB connection
Class.forName(“com.mysql.jdbc.Driver”).newInstance();
con = DriverManager.getConnection(“jdbc:mysql://localhost/DB-NAME”,”root”,””);
System.out.println(“Connection Success!!”);
s = con.createStatement();
String query = “select * from TABLE-NAME“;
rs = s.executeQuery(query);
if(rs.next()) {
System.out.println(rs.getString(1) + “\t\t” + rs.getString(2));
}
}
}
January 19th, 2012 at 3:08 pm
can you give it according to my frame. cause i am weak in netbeans. The code given by you is showing error in my project ‘try’ which i had commented earlier.
January 19th, 2012 at 3:25 pm
@Sahil :
just create a new java file named “select.java” and paste the above code in it.
Also make the changes in code for the one’s in CAPITAL.
i.e. : TABLE-NAME :- Enter the table from which you want to retrieve details and DB-NAME :- whichever database the above table lies in.