Skip to content

hamzagoc/JDBCProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JDBCProject

##Installation

Firstly, you must add mysql-connector on your project ==> http://mvnrepository.com/artifact/mysql/mysql-connector-java Then add package "com.hamzaburakhan.jdbc" on your project and after that you can use it.

##Using ###User Class

@Table("tablename")
public class User {
	
	private int id;

	@RealName("name")
	private String ad;

	@RealName("lastName")
	private String soyad;

	@Embeded
	private Adress adres;
	
	getter and setters...

###Adress Class

@Table("addresses")
public class User {
	
	@RealName("id")
	private int id;

	@RealName("il")
	private String il;
	
	@RealName("ilce")
	private String ilce;
	
	getter and setters...

###Insert example

DatabaseConnection dbconnection = new DatabaseConnection(HOST, DB, USERNAME, PASSWORD, true); // true is encode_utf8
dbconnection.showSqlCode(true);	
User user = new User(20,"New","Record");
dbconnection.insertRow(user);

###Select example

DatabaseConnection dbconnection = new DatabaseConnection(HOST, DB, USERNAME, PASSWORD, true);
String selectSQL = "Select * FROM tabloadi,addresses Where id < ? AND tabloadi.adres_id=addresses.id ";
//Sorgundaki soru işaretleri için parametreleri giriyorsun.Sırasıyla girmen önemli.
//You must enter the parameters for the question marks in your query. It is important to be sequential.
QueryParams paramaters = new QueryParams();
paramaters.addParams(8);
List<User> users = dbconnection.selectRecods(selectSQL, paramaters,User.class);

###Update example

DatabaseConnection dbconnection = new DatabaseConnection(HOST, DB, USERNAME, PASSWORD, true);
String updateSQL = "UPDATE tabloadi SET name=?, lastname=? WHERE id=?";
//Sorgundaki soru işaretleri için parametreleri giriyorsun.Sırasıyla girmen önemli.
//You must enter the parameters for the question marks in your query. It is important to be sequential.
QueryParams params = new QueryParams();
params.addParams("Update");
params.addParams("Example");
params.addParams(6);
dbconnection.update(updateSQL, params);

###Delete example

DatabaseConnection dbconnection = new DatabaseConnection(HOST, DB, USERNAME, PASSWORD, true);
dbconnection.showSqlCode(true);
String deleteSQL = "DELETE FROM tabloadi WHERE id=? AND name=?";
//Sorgundaki soru işaretleri için parametreleri giriyorsun.Sırasıyla girmen önemli.
//You must enter the parameters for the question marks in your query. It is important to be sequential.
QueryParams paramaters = new QueryParams();
paramaters.addParams(20);
paramaters.addParams("New");
int result = dbconnection.delete(deleteSQL, paramaters);
System.out.println(result); // Number of affected rows

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages