Select All Rows From Table

Leave a reply                     

Java MySql Select

How to Select MySql Table Data in Java?

Java MySql ResultSet

Java Select Query Using Statement

Query: SELECT columnname1, columnname2 FROM tablename
Above query selects all rows from table tablename contains data for columns columnname1 and columnname2 Continue reading

Update Table in Java

Leave a reply                     

How to Update MySql Table in Java?

Java Update Query

Update Value Using Java

Java Update Mysql Table Data

executeUpdate: This method of Statement is used for CREATE/INSERT/UPDATE/DELETE queries.
Following query used to update data
UPDATE tablename set columnname2 = ‘http://www.’ where columnname1 = ’1′
tablename the table in which values are updated.
columnname2 name of column to be changed. Continue reading

Insert Into Table

Leave a reply                     

Insert Into MySql Table in Java

Java MySql Insert

MySql Insert Table Using PreparedStatement

How to Insert Data In MySql Database Table in Java

PreparedStatement: Is used to complied once and then executed in loop to insert multiple values in database table tablename in column columnname2, columnname1 is not mentioned since it is auto_increment. Continue reading

Insert in Table

Leave a reply                     

Insert in Table in Java

MySql Insert into Table

Java Insert in MySql table

How to Insert Data in MySql Table in Java

Following INSERT statement is used to insert data “www.” in database table tablename in column columnname2, the value for column columnname1 automatically inserted since it is auto increment column.
INSERT INTO tablename(columnname2) values (‘www.’) Continue reading

Create Table

Leave a reply                     

Create Table in Java

MySql Create Table

Java Create Table

How to Create Table In MySql in Java?

Following program creates table tablename in MySql database databasename.
columnname1 and columnname2 are name of columns in table.
auto_increment is used to make column auto increment.
primary key makes columnname1 primary key.

package raghuwansh.java.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class CreateTable {

	 * @param args
	public static void main(String[] args) {
		try {
			Connection connection = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/databasename", "root", "");
			Statement statement = connection.createStatement();
					.executeUpdate("CREATE TABLE tablename(columnname1 int(5) auto_increment primary key, columnname2 varchar(128))");
		} catch (SQLException e) {
		} catch (ClassNotFoundException e) {