Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.RS09HD.model;
- import java.sql.*;
- import java.util.Map;
- import com.RS09HD.MySQL.SqlManager;
- /**
- * Represents a object, primarily manages it's examine option.
- */
- public class ObjectDefinition {
- // JDBC driver name and database URL
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String DB_URL = "jdbc:mysql://localhost:3306/rs09hd";
- // Database credentials
- static final String USER = "server";
- static final String PASS = "Runescape09";
- private static String examine;
- public static String query(int id) throws SQLException {
- System.out.println("ID:" + id);
- Connection conn = null;
- PreparedStatement stmt = null;
- try{
- // Register JDBC driver
- Class.forName("com.mysql.jdbc.Driver");
- // Open a connection
- System.out.println("Connecting to database...");
- conn = DriverManager.getConnection(DB_URL,USER,PASS);
- }catch(SQLException se){
- //Handle errors for JDBC
- se.printStackTrace();
- }catch(Exception e){
- //Handle errors for Class.forName
- e.printStackTrace();
- }
- // Execute a query
- System.out.println("Creating statement...");
- PreparedStatement ps = conn.prepareStatement( "SELECT * FROM object_examines WHERE id = ? " ) ;
- //Bind values into the parameter
- ps.setInt( 1, id) ;
- System.out.println(ps);
- ResultSet rs = ps.executeQuery() ;
- System.out.println(rs);
- while(rs.next()){
- //Retrieve by column name
- String examine = rs.getString("examine");
- //Display values
- System.out.println("Examine: " + examine);
- }
- return examine;
- }
- public static ObjectDefinition forId(int id) {
- try {
- query(id);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- private int id;
- public int getId() {
- return id;
- }
- public String getExamine() {
- return examine;
- }
- public static ObjectDefinition produceDefinition(int id) {
- ObjectDefinition def = new ObjectDefinition();
- def.id = id;
- String idString;
- idString = new String( "Object ID: " + def.id);
- def.examine = idString;
- return def;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement