This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PreparedStatement ps = connection.prepareStatement("INSERT INTO users (first_name, email, last_name) VALUES (?, ?, ?)", new String[]{"id"}); | |
ps.setObject(1, "John"); | |
ps.setObject(2, "Doe"); | |
ps.setObject(3, "john@doe.com"); | |
ps.executeUpdate(); | |
ResultSet rs = ps.getGeneratedKeys(); | |
rs.next(); | |
Object id = rs.getObject(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void close() { | |
try { | |
Connection connection = ConnectionsAccess.getConnection(dbName); | |
if(connection == null){ | |
throw new DBException("cannot close connection '" + dbName + "' because it is not available"); | |
} | |
StatementCache.instance().cleanStatementCache(connection); | |
connection.close(); | |
LogFilter.log(logger, "Closed connection: " + connection); | |
} catch (Exception e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.lang.reflect.InvocationHandler; | |
import java.lang.reflect.Method; | |
import java.lang.reflect.Proxy; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class ConnectionDemo { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List users = User.where("id not in (select user_id from restricted_users)"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Person p = new Person(); | |
p.set("first_name", "Marilyn","last_name", "Monroe"); | |
p.set("dob", "1926/6/1"); //wrong format | |
p.validate(); | |
System.out.println(p.errors().get("dob")); //prints out: attribute dob does not conform to format: yyyy-MM-dd | |
p.set("dob", "1926-06-01"); //right format | |
p.validate(); | |
System.out.println(p.get("dob").getClass()); //prints out: class java.sql.Date | |
System.out.println(p.get("dob")); //prints out: 1926-06-01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<target name="-post-compile"> | |
<java classname="org.javalite.instrumentation.Main" failonerror="true"> | |
<sysproperty key="outputDirectory" value="${build.classes.dir}"/> | |
<classpath> | |
<pathelement path="${build.classes.dir}" /> | |
<pathelement path="${javac.classpath}" /> | |
<pathelement path="${javac.processorpath}" /> | |
</classpath> | |
</java> | |
</target> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Tickets> tickets = Person.where("name = ?", "Bill"); | |
for(Ticket t: tickets) | |
System.out.println(t); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class City extends Model{ | |
public void beforeSave(){ | |
set("province_id" Convert.toInteger(get("province_id"))); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PlayerItemDefinition record = new PlayerItemDefinition(); | |
record.set("id", "this is id string"); | |
record.set("player_id", "t123"); | |
record.saveIt(); | |
PlayerItemDefinition.findAll().dump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void test(){ | |
PlayerItemDefinition record = new PlayerItemDefinition(); | |
record.set("id", "this is id string"); | |
record.set("player_id", "t123"); | |
record.saveIt(); | |
PlayerItemDefinition definition = PlayerItemDefinition.findFirst("id = ? and player_id = ?", "this is id string", "t123"); |
OlderNewer