Android Battery Monitor

Programming/Android 2013. 4. 29. 18:43 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Android Battery Monitor Code


batteryUsePerSec 를 수정하여 사용하세요



	public TextView batteryUsePerSec; // 배터리 Text View

	public void onCreate(Bundle savedInstanceState) {
		......
		batteryUsePerSec = (TextView) findViewById(R.id.batteryUsePerSec);
		......
        }

	public void onResume() {
		......
		IntentFilter filter = new IntentFilter();
		filter.addAction(Intent.ACTION_BATTERY_CHANGED);
		registerReceiver(mBRBattery, filter);
		......
	}

	BroadcastReceiver mBRBattery = new BroadcastReceiver()
	{

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			String action = intent.getAction();
			if (action.equals(Intent.ACTION_BATTERY_CHANGED))
			{
				onBatteryChanged(intent);
			}
		}

		private void onBatteryChanged(Intent intent) {
			// TODO Auto-generated method stub
			int scale, level, ratio;
			scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
			level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100);
			ratio = level * 100 / scale;
			
			batteryUsePerSec.setText(ratio + "");
			Log.d(ActivityTag, "onBatteryChanged()" + ratio);
		}
		
	};


'Programming > Android' 카테고리의 다른 글

파일 이름 일괄 변경 DarkNamer  (0) 2013.05.05
MyLocation Class  (0) 2013.05.04
Android google Map v2  (2) 2013.04.27
안드로이드 APK 추출하기  (0) 2013.04.25
Thread 와 Handler 테스트  (0) 2013.04.13

JAVA MYSQL ANDROID REST 활용

Programming/JAVA,JSP 2013. 4. 28. 17:15 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
REST 사용방법 http://192.168.0.3:8182/books http://192.168.0.3:8182/books/where/OReilly http://192.168.0.3:8182/books/ insert/"제목"/"저자"/"가격' REST 서버
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.restlet.Application;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.Server;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;

public class test extends Application {
	public static Connection makeConnection() {
		String url = "jdbc:mysql://localhost:3307/book_db";
		String id = "root";
		String password = "green";
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("드라이버 적재 성공");
			con = DriverManager.getConnection(url, id, password);
			System.out.println("데이터베이스 연결 성공");
		} catch (ClassNotFoundException e) {
			System.out.println("드라이버를 찾을 수 없습니다.");
		} catch (SQLException e) {
			System.out.println("연결에 실패하였습니다.");
		}
		return con;
	}

	public static Statement stmt;

	public static void main(String[] args) throws Exception {
		Connection con = makeConnection();
		stmt = con.createStatement();
		Server server = new Server(Protocol.HTTP, 8182);
		server.setNext(new test());
		server.start();
	}

	public static String selectBooks(Statement stmt) throws SQLException {
		ResultSet rs = stmt.executeQuery("SELECT * FROM books");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			String publisher = rs.getString("publisher");
			String year = rs.getString("year");
			if (title != null) {
				result += id + " " + title + " " + publisher + " " + year
						+ "\n";
			}
		}
		return result;
	}

	public static String selectBooks(Statement stmt, String name)
			throws SQLException {
		ResultSet rs = stmt
				.executeQuery("SELECT * FROM books WHERE publisher = '" + name
						+ "'");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			String publisher = rs.getString("publisher");
			String year = rs.getString("year");
			if (title != null) {
				result += id + " " + title + " " + publisher + " " + year
						+ "\n";
			}
		}
		return result;
	}

	@Override
	public Restlet createInboundRoot() {
		Router router = new Router();
		router.attach("http://localhost:8182/books", restlet1);
		router.attach("http://localhost:8182/books/where/{name}", restlet2);
		router.attach(
				"http://localhost:8182/books/insert/{title}/{publisher}/{year}/{price}",
				restlet3);
		router.attach("http://localhost:8182/datas/{year}/{month}/{day}",
				restlet4);
		router.attach("http://192.168.0.3:8182/books", restlet1);
		router.attach("http://192.168.0.3:8182/books/where/{name}", restlet2);
		router.attach(
				"http://192.168.0.3:8182/books/insert/{title}/{publisher}/{year}/{price}",
				restlet3);
		router.attach("http://192.168.0.3:8182/datas/{year}/{month}/{day}",
				restlet4);
		// (title, publisher, year, price)
		return router;
	}

	public Restlet restlet4 = new Restlet(getContext()) {
		@Override
		public void handle(Request request, Response response) {
			// Print the user name of the requested orders
			String year = (String) request.getAttributes().get("year");
			String month = (String) request.getAttributes().get("month");
			String day = (String) request.getAttributes().get("day");

			String message = "";
			try {
				message += selectDatas(stmt, year, month, day);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};

	public static String selectDatas(Statement stmt, String year, String month,
			String day) throws SQLException {
		ResultSet rs = stmt.executeQuery("SELECT * FROM datas WHERE year = "
				+ year + " && month =" + month + "&& day=" + day + ";");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("data_id");
			String contents = rs.getString("contents");
			if (contents != null) {
				result += id + " " + year + " " + month + " " + day + " "
						+ contents + "\n";
			}
		}
		return result;
	}

	public Restlet restlet3 = new Restlet(getContext()) {
		@Override
		public void handle(Request request, Response response) {
			// Print the user name of the requested orders
			String title = (String) request.getAttributes().get("title");
			String publisher = (String) request.getAttributes()
					.get("publisher");
			String year = (String) request.getAttributes().get("year");
			String price = (String) request.getAttributes().get("price");
			try {
				insertBooks(stmt, title, publisher, year, price);
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			String message = "";
			try {
				message += selectBooks(stmt);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}

		private void insertBooks(Statement stmt, String title,
				String publisher, String year, String price)
				throws SQLException {
			// TODO Auto-generated method stub
			// INSERT INTO books (title, publisher, year, price)
			// VALUES('Operating System Concepts', 'Wiley', '2003', 30700);
			stmt.execute("INSERT INTO books (title, publisher, year, price)"
					+ "VALUES('" + title + "','" + publisher + "','" + year
					+ "'," + price + ");");
		}
	};

	public Restlet restlet2 = new Restlet(getContext()) {
		@Override
		public void handle(Request request, Response response) {
			// Print the user name of the requested orders
			String name = (String) request.getAttributes().get("name");
			String message = "";
			try {
				message += selectBooks(stmt, name);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};
	public Restlet restlet1 = new Restlet() {
		public void handle(Request request, Response response) {
			String message = "";
			try {
				message += selectBooks(stmt);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};
}

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA JNI  (0) 2013.05.01
Eclipse Tips  (0) 2013.04.30
JAVA MYSQL 활용 4 Android App  (0) 2013.04.28
JAVA MYSQL 활용 3  (0) 2013.04.28
MYSQL REST 실습 코드 2  (0) 2013.04.28

JAVA MYSQL 활용 4 Android App

Programming/JAVA,JSP 2013. 4. 28. 15:16 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {
	TextView result;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	public void mOnClick(View v) {
		Log.d("mOnClick", "mOnClick s1");
		String html;
		downloadThread dt = new downloadThread("http://192.168.0.3:8182/books");
		result = (TextView) findViewById(R.id.text);
		dt.start();
	}

	class downloadThread extends Thread {

		public String addr;

		public downloadThread(String addr) {
			this.addr = addr;
		}

		public void run() {

			StringBuilder html = new StringBuilder();
			try {
				URL url = new URL(addr);
				HttpURLConnection conn = (HttpURLConnection) url
						.openConnection();
				if (conn != null) {
					conn.setConnectTimeout(10000);
					conn.setUseCaches(false);
					if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
						BufferedReader br = new BufferedReader(
								new InputStreamReader(conn.getInputStream()));
						while (true) {
							String line = br.readLine();
							if (line == null)
								break;
							html.append(line + '\n');
						}
						br.close();
					}
					conn.disconnect();
				}
			} catch (Exception ex) {
			}
			Message msg = new Message();
			msg.obj = html.toString();
			mHandler.sendMessage(msg);
		};
	};

	Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			result.setText((String) msg.obj);
		};
	};
}

'Programming > JAVA,JSP' 카테고리의 다른 글

Eclipse Tips  (0) 2013.04.30
JAVA MYSQL ANDROID REST 활용  (0) 2013.04.28
JAVA MYSQL 활용 3  (0) 2013.04.28
MYSQL REST 실습 코드 2  (0) 2013.04.28
MYSQL & REST 실습 코드  (0) 2013.04.28

JAVA MYSQL 활용 3

Programming/JAVA,JSP 2013. 4. 28. 14:20 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.restlet.Application;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.Server;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;

public class test extends Application{
	public static Connection makeConnection() {
		String url = "jdbc:mysql://localhost/book_db";
		String id = "root";
		String password = "green";
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("드라이버 적재 성공");
			con = DriverManager.getConnection(url, id, password);
			System.out.println("데이터베이스 연결 성공");
		} catch (ClassNotFoundException e) {
			System.out.println("드라이버를 찾을 수 없습니다.");
		} catch (SQLException e) {
			System.out.println("연결에 실패하였습니다.");
		}
		return con;
	}
	public static Statement stmt;
	public static void main(String[] args) throws Exception {
		Connection con = makeConnection();
		stmt = con.createStatement();
		Server server = new Server(Protocol.HTTP, 8182);
		server.setNext(new test());
		server.start();
	}
	public static String selectBooks(Statement stmt) throws SQLException {
		ResultSet rs = stmt.executeQuery("SELECT * FROM books");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			String publisher = rs.getString("publisher");
			String year = rs.getString("year");
			if( title != null)
			{
				result += id + " " + title +" " + publisher +" " + year + "\n";
			}
		}
		return result;
	}
	public static String selectBooks(Statement stmt, String name) throws SQLException {
		ResultSet rs = stmt.executeQuery("SELECT * FROM books WHERE publisher = '" + name + "'");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			String publisher = rs.getString("publisher");
			String year = rs.getString("year");
			if( title != null)
			{
				result += id + " " + title +" " + publisher +" " + year + "\n";
			}
		}
		return result;
	}
	@Override
	public Restlet createInboundRoot() {
		Router router = new Router();
		router.attach("http://localhost:8182/books", restlet1);
		router.attach("http://localhost:8182/books/where/{name}", restlet2);
		router.attach("http://localhost:8182/books/insert/{title}/{publisher}/{year}/{price}", restlet3);
		//(title, publisher, year, price)
		return router;
	}

	public Restlet restlet3 = new Restlet(getContext()) {
		@Override
		public void handle(Request request, Response response) {
			// Print the user name of the requested orders
			String title = (String)request.getAttributes().get("title");
			String publisher = (String)request.getAttributes().get("publisher");
			String year = (String)request.getAttributes().get("year");
			String price = (String)request.getAttributes().get("price");
			try {
				insertBooks(stmt,title,publisher,year,price);
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			String message = "";
			try {
				message += selectBooks(stmt);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}

		private void insertBooks(Statement stmt, String title,
				String publisher, String year, String price) throws SQLException {
			// TODO Auto-generated method stub
			//INSERT INTO books (title, publisher, year, price)
			//VALUES('Operating System Concepts', 'Wiley', '2003', 30700);
			stmt.execute("INSERT INTO books (title, publisher, year, price)"
					+"VALUES('"+title+"','"+publisher+"','"+year+"',"+price+");");
		}
	};

	public Restlet restlet2 = new Restlet(getContext()) {
		@Override
		public void handle(Request request, Response response) {
			// Print the user name of the requested orders
			String name = (String)request.getAttributes().get("name");
			String message = "";
			try {
				message += selectBooks(stmt, name);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};
	public Restlet restlet1 = new Restlet() {
		public void handle(Request request, Response response) {
			String message = "";
			try {
				message += selectBooks(stmt);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};
}

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA MYSQL ANDROID REST 활용  (0) 2013.04.28
JAVA MYSQL 활용 4 Android App  (0) 2013.04.28
MYSQL REST 실습 코드 2  (0) 2013.04.28
MYSQL & REST 실습 코드  (0) 2013.04.28
JAVA MYSQL 활용 1  (0) 2013.04.27

MYSQL REST 실습 코드 2

Programming/JAVA,JSP 2013. 4. 28. 13:34 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.restlet.Application;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.Server;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;

public class test extends Application{
	public static Connection makeConnection() {
		String url = "jdbc:mysql://localhost/book_db";
		String id = "root";
		String password = "green";
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("드라이버 적재 성공");
			con = DriverManager.getConnection(url, id, password);
			System.out.println("데이터베이스 연결 성공");
		} catch (ClassNotFoundException e) {
			System.out.println("드라이버를 찾을 수 없습니다.");
		} catch (SQLException e) {
			System.out.println("연결에 실패하였습니다.");
		}
		return con;
	}
	public static Statement stmt;
	public static void main(String[] args) throws Exception {
		Connection con = makeConnection();
		stmt = con.createStatement();
		Server server = new Server(Protocol.HTTP, 8182);
		server.setNext(new test());
		server.start();
	}
	public static String selectBooks(Statement stmt) throws SQLException {
		ResultSet rs = stmt.executeQuery("SELECT * FROM books");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			if( title != null)
			{
				result += id + " " + title + "\n";
			}
		}
		return result;
	}
	public static String selectBooks(Statement stmt, String name) throws SQLException {
		ResultSet rs = stmt.executeQuery("SELECT * FROM books WHERE publisher = '" + name + "'");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			if( title != null)
			{
				result += id + " " + title + "\n";
			}
		}
		return result;
	}
	@Override
	public Restlet createInboundRoot() {
		Router router = new Router();
		router.attach("http://localhost:8182/books", restlet1);
		router.attach("http://localhost:8182/books/where/{name}", restlet2);

		return router;
	}

	public Restlet restlet2 = new Restlet(getContext()) {
		@Override
		public void handle(Request request, Response response) {
			// Print the user name of the requested orders
			String name = (String)request.getAttributes().get("name");
			String message = "";
			try {
				message += selectBooks(stmt, name);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};
	public Restlet restlet1 = new Restlet() {
		public void handle(Request request, Response response) {
			String message = "";
			try {
				message += selectBooks(stmt);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};
}

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA MYSQL 활용 4 Android App  (0) 2013.04.28
JAVA MYSQL 활용 3  (0) 2013.04.28
MYSQL & REST 실습 코드  (0) 2013.04.28
JAVA MYSQL 활용 1  (0) 2013.04.27
JAVA MYSQL Test  (0) 2013.04.27

MYSQL & REST 실습 코드

Programming/JAVA,JSP 2013. 4. 28. 12:12 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.restlet.Application;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.Server;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;

public class test extends Application{
	public static Connection makeConnection() {
		String url = "jdbc:mysql://localhost/book_db";
		String id = "root";
		String password = "green";
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("드라이버 적재 성공");
			con = DriverManager.getConnection(url, id, password);
			System.out.println("데이터베이스 연결 성공");
		} catch (ClassNotFoundException e) {
			System.out.println("드라이버를 찾을 수 없습니다.");
		} catch (SQLException e) {
			System.out.println("연결에 실패하였습니다.");
		}
		return con;
	}
	public static Statement stmt;
	public static void main(String[] args) throws Exception {
		Connection con = makeConnection();
		stmt = con.createStatement();
		Server server = new Server(Protocol.HTTP, 8182);
		server.setNext(new test());
		server.start();
	}
	public static String selectBooks(Statement stmt) throws SQLException {
		ResultSet rs = stmt.executeQuery("SELECT * FROM books");
		String result = "";
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			if( title != null)
			{
				result += id + " " + title + "\n";
			}
		}
		return result;
	}
	@Override
	public Restlet createInboundRoot() {
		Router router = new Router();
		router.attach("http://localhost:8182/books", restlet1);
		return router;
	}

	public Restlet restlet1 = new Restlet() {
		public void handle(Request request, Response response) {
			String message = "";
			try {
				message += selectBooks(stmt);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.setEntity(message, MediaType.TEXT_PLAIN);
		}
	};
}

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA MYSQL 활용 3  (0) 2013.04.28
MYSQL REST 실습 코드 2  (0) 2013.04.28
JAVA MYSQL 활용 1  (0) 2013.04.27
JAVA MYSQL Test  (0) 2013.04.27
JAVA 코드 그럴듯 하게 보이게 하기?!  (1) 2013.04.27

JAVA MYSQL 활용 1

Programming/JAVA,JSP 2013. 4. 27. 17:08 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1. 데이터 삽입 INSERT


INSERT INTO books (title, publisher, year, price)

  VALUES('Operating System Concepts', 'Wiley', '2003', 30700);

INSERT INTO books (title, publisher, year, price)

  VALUES('Head First PHP and MYSQL', 'OReilly', '2009', 58000);

INSERT INTO books (title, publisher, year, price)

  VALUES('C Programming Language', 'Prentice-Hall', '1989', 35000);

INSERT INTO books (title, publisher, year, price)

  VALUES('Head First SQL', 'OReilly', '2007', 43700);



2. 데이터 확인 

(지난 코드 재실행)



'Programming > JAVA,JSP' 카테고리의 다른 글

MYSQL REST 실습 코드 2  (0) 2013.04.28
MYSQL & REST 실습 코드  (0) 2013.04.28
JAVA MYSQL Test  (0) 2013.04.27
JAVA 코드 그럴듯 하게 보이게 하기?!  (1) 2013.04.27
restlet download restlet-jse-2.1.2  (0) 2013.04.27

JAVA MYSQL Test

Programming/JAVA,JSP 2013. 4. 27. 17:05 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

JAVA MYSQL Test


1. MYSQL 설치


http://www.mysql.com/downloads/installer/


1.2 MYSQL JAVA 드라이버 설치


http://www.mysql.com/downloads/connector/j/


ZIP 파일 압축 해제 후




jar 파일 을 복사하여


내 컴퓨터의 


Java\jre7\lib\ext


폴더에 붙여넣기 합니다.





2. MYSQL Table 생성


DROP DATABASE book_db;

CREATE DATABASE book_db;

USE book_db;

CREATE TABLE books(

book_id INT NOT NULL auto_increment,

title VARCHAR(50),

publisher VARCHAR(30),

year VARCHAR(10),

price INT,

PRIMARY KEY(book_id)

);


3. TEST CODE





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

public class test {
	public static Connection makeConnection() {
		String url = "jdbc:mysql://localhost/book_db";
		String id = "root";
		String password = "green";
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("드라이버 적재 성공");
			con = DriverManager.getConnection(url, id, password);
			System.out.println("데이터베이스 연결 성공");
		} catch (ClassNotFoundException e) {
			System.out.println("드라이버를 찾을 수 없습니다.");
		} catch (SQLException e) {
			System.out.println("연결에 실패하였습니다.");
		}
		return con;
	}

	public static void main(String[] args) throws SQLException {
		Connection con = makeConnection();
		Statement stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT * FROM books");
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			System.out.println(id + " " + title);
		}
	}
}

3. 데이터베이스 연결 확인




'Programming > JAVA,JSP' 카테고리의 다른 글

MYSQL & REST 실습 코드  (0) 2013.04.28
JAVA MYSQL 활용 1  (0) 2013.04.27
JAVA 코드 그럴듯 하게 보이게 하기?!  (1) 2013.04.27
restlet download restlet-jse-2.1.2  (0) 2013.04.27
RESTLET Point  (0) 2013.04.21
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

출처 : http://ggons.tistory.com/35



1. js 및 css 다운로드

 - http://alexgorbatchev.com/SyntaxHighlighter/download/ 에서 zip 파일 내려받기

syntaxhighlighter_3.0.83.zip


 - 임의의 폴더에 압축 해제시켜 놓습니다.


2. js 및 css 등록

 - Admin → 꾸미기 → HTML/CSS 편집
 - "파입업로드" 탭에서 위에서 압축해제한 파일 중 scripts, styles 폴더의 모든 js 및 css를 업로드 합니다.

몇년을 귀차니즘으로 버티다가 기어이 "소스코드 문법 강조 스타일"을 적용해본다. 짜잉나는 네이버 블로그를 떠난 이유도 이런 자유도 때문이 아닐까 한다.

3. skin.html 수정

 - HTML/CSS 탭 내의 skin.html 내용중 Head 태그내에 아래를 붙여넣음
 - Required 주석이 붙은 것은 반드시 붙여넣어야 하고..
 - Optional 붙은 주석은 이름을 잘 보고 쓰고 싶은 것만 넣으면 됩니다.

<!-- Required including -->
<script type="text/javascript" src="./images/shCore.js"></script>
<link rel="stylesheet" type="text/css" href="./images/shCore.css" />
<link rel="stylesheet" type="text/css" href="./images/shThemeDefault.css" />

<!-- Optional including -->
<script type="text/javascript" src="./images/shBrushAppleScript.js"></script>
<script type="text/javascript" src="./images/shBrushAS3.js"></script>
<script type="text/javascript" src="./images/shBrushBash.js"></script>
<script type="text/javascript" src="./images/shBrushColdFusion.js"></script>
<script type="text/javascript" src="./images/shBrushCpp.js"></script>
<script type="text/javascript" src="./images/shBrushCSharp.js"></script>
<script type="text/javascript" src="./images/shBrushCss.js"></script>
<script type="text/javascript" src="./images/shBrushDelphi.js"></script>
<script type="text/javascript" src="./images/shBrushDiff.js"></script>
<script type="text/javascript" src="./images/shBrushErlang.js"></script>
<script type="text/javascript" src="./images/shBrushGroovy.js"></script>
<script type="text/javascript" src="./images/shBrushJava.js"></script>
<script type="text/javascript" src="./images/shBrushJavaFX.js"></script>
<script type="text/javascript" src="./images/shBrushJScript.js"></script>
<script type="text/javascript" src="./images/shBrushPerl.js"></script>
<script type="text/javascript" src="./images/shBrushPhp.js"></script>
<script type="text/javascript" src="./images/shBrushPlain.js"></script>
<script type="text/javascript" src="./images/shBrushPowerShell.js"></script>
<script type="text/javascript" src="./images/shBrushPython.js"></script>
<script type="text/javascript" src="./images/shBrushRuby.js"></script>
<script type="text/javascript" src="./images/shBrushSass.js"></script>
<script type="text/javascript" src="./images/shBrushScala.js"></script>
<script type="text/javascript" src="./images/shBrushSql.js"></script>
<script type="text/javascript" src="./images/shBrushVb.js"></script>
<script type="text/javascript" src="./images/shBrushXml.js"></script>

<!-- Required including -->
<script type="text/javascript">
    SyntaxHighlighter.all();
</script>


4. 소스코드 작성

 - 에디터 우측상단 html 체크박스 체크 후 HTML 수정모드로 진입하여
 - 아래처럼 pre 태그 내에 소스코드를 써주면 됩니다.

1
2
3
4
<pre class="brush:java">public class A {
 
}
</pre>

5. 테스트 결과

1
2
3
public class A {
 
}


6. 사용 가능한 brush 목록

 - http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes 참조

Brush nameBrush aliasesFile name
ActionScript3as3, actionscript3shBrushAS3.js
Bash/shellbash, shellshBrushBash.js
ColdFusioncf, coldfusionshBrushColdFusion.js
C#c-sharp, csharpshBrushCSharp.js
C++cpp, cshBrushCpp.js
CSScssshBrushCss.js
Delphidelphi, pas, pascalshBrushDelphi.js
Diffdiff, patchshBrushDiff.js
Erlangerl, erlangshBrushErlang.js
GroovygroovyshBrushGroovy.js
JavaScriptjs, jscript, javascriptshBrushJScript.js
JavajavashBrushJava.js
JavaFXjfx, javafxshBrushJavaFX.js
Perlperl, plshBrushPerl.js
PHPphpshBrushPhp.js
Plain Textplain, textshBrushPlain.js
PowerShellps, powershellshBrushPowerShell.js
Pythonpy, pythonshBrushPython.js
Rubyrails, ror, rubyshBrushRuby.js
ScalascalashBrushScala.js
SQLsqlshBrushSql.js
Visual Basicvb, vbnetshBrushVb.js
XMLxml, xhtml, xslt, html, xhtmlshBrushXml.js

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA MYSQL 활용 1  (0) 2013.04.27
JAVA MYSQL Test  (0) 2013.04.27
restlet download restlet-jse-2.1.2  (0) 2013.04.27
RESTLET Point  (0) 2013.04.21
RESTlet HelloWorld  (0) 2013.04.21

restlet download restlet-jse-2.1.2

Programming/JAVA,JSP 2013. 4. 27. 14:49 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

restlet-jse-2.1.2


restlet.org 다운로드 사이트가 일부 익스플로러에서 접속되지 않아서 분할 압축으로 올립니다.



restlet-jse-2.1.2.vol1.egg


restlet-jse-2.1.2.vol2.egg


restlet-jse-2.1.2.vol3.egg


restlet-jse-2.1.2.vol4.egg


restlet-jse-2.1.2.vol5.egg


'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA MYSQL Test  (0) 2013.04.27
JAVA 코드 그럴듯 하게 보이게 하기?!  (1) 2013.04.27
RESTLET Point  (0) 2013.04.21
RESTlet HelloWorld  (0) 2013.04.21
JAVA 로 Word 문서 만들기  (0) 2013.03.29