336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

class DraggableComponent extends JComponent

{

 

    /** If sets <b>TRUE</b> this component is draggable */

    private boolean draggable = true;

    /**

     * 2D Point representing the coordinate where mouse is, relative parent

     * container

     */

    protected Point anchorPoint;

    /** Default mouse cursor for dragging action */

    protected Cursor draggingCursor = Cursor

           .getPredefinedCursor(Cursor.HAND_CURSOR);

    /**

     * If sets <b>TRUE</b> when dragging component, it will be painted over each

     * other (z-Buffer change)

     */

    protected boolean overbearing = false;

 

    public DraggableComponent()

    {

        addDragListeners();

        setOpaque(true);

        setBackground(new Color(240, 240, 240));

    }

 

    /**

     * Add Mouse Motion Listener with drag function

     */

    private void addDragListeners()

    {

        /**

         * This handle is a reference to THIS because in next Mouse Adapter

         * "this" is not allowed

         */

        final DraggableComponent handle = this;

        addMouseMotionListener(new MouseAdapter()

        {

 

           @Override

           public void mouseMoved(MouseEvent e)

           {

               anchorPoint = e.getPoint();

           setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

           }

 

           @Override

           public void mouseDragged(MouseEvent e)

           {

               int anchorX = anchorPoint.x;

               int anchorY = anchorPoint.y;

 

               Point parentOnScreen = getParent().getLocationOnScreen();

               Point mouseOnScreen = e.getLocationOnScreen();

               Point position = new Point(mouseOnScreen.x - parentOnScreen.x

                       - anchorX, mouseOnScreen.y - parentOnScreen.y - anchorY);

               setLocation(position);

 

               // Change Z-Buffer if it is "overbearing"

               if (overbearing)

               {

                   getParent().setComponentZOrder(handle, 0);

                   repaint();

               }

           }

        });

    }

 

    @Override

    protected void paintComponent(Graphics g)

    {

        super.paintComponent(g);

        if (isOpaque())

        {

           g.setColor(getBackground());

           g.fillRect(0, 0, getWidth(), getHeight());

        }

    }

 

    private void removeDragListeners()

    {

        for (MouseMotionListener listener : this.getMouseMotionListeners())

        {

           removeMouseMotionListener(listener);

        }

        setCursor(Cursor.getDefaultCursor());

    }

}


http://www.codeproject.com/Articles/116088/Draggable-Components-in-Java-Swing

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

JAVA Console Token 구현  (0) 2013.08.07
JAVA 제네릭을 사용한 Store Class  (0) 2013.08.07
JAVA Swing 두개의 판넬을 겹치기  (0) 2013.08.03
JAVA JNI  (0) 2013.05.01
Eclipse Tips  (0) 2013.04.30
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
import java.awt.*;
import javax.swing.*;

class BgPanel extends JPanel {
    Image bg = new ImageIcon("water.jpg").getImage();
    @Override
    public void paintComponent(Graphics g) {
        g.drawImage(bg, 0, 0, getWidth(), getHeight(), this);
    }
}

class LoginPanel extends JPanel {
    LoginPanel() {
        setOpaque(false);
        setLayout(new FlowLayout());
        add(new JLabel("username: ")); add(new JTextField(10));
        add(new JLabel("password: ")); add(new JPasswordField(10));
    }
}

public class FrameTestBase extends JFrame {
    public static void main(String args[]) {
        JPanel bgPanel = new BgPanel();
        bgPanel.setLayout(new BorderLayout());
        bgPanel.add(new LoginPanel(), BorderLayout.CENTER);

        FrameTestBase t = new FrameTestBase();
        t.setContentPane(bgPanel);
        t.setDefaultCloseOperation(EXIT_ON_CLOSE);
        t.setSize(250, 100);
        t.setVisible(true);
    }
}



http://stackoverflow.com/questions/7092067/adding-a-background-image-to-a-panel-containing-other-components



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

JAVA 제네릭을 사용한 Store Class  (0) 2013.08.07
JAVA DRAG 가능한 Component 만들기  (0) 2013.08.03
JAVA JNI  (0) 2013.05.01
Eclipse Tips  (0) 2013.04.30
JAVA MYSQL ANDROID REST 활용  (0) 2013.04.28

Intent 정리

Programming/Android 2013. 5. 9. 21:19 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
//show webapp:

Uri uri = Uri.parse("http://www.google.com");
Intent it  = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);

//show maps:
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it); 

//show ways
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);

//call dial program
Uri uri = Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL, uri);  
startActivity(it);  

Uri uri = Uri.parse("tel.xxxxxx");
Intent it =new Intent(Intent.ACTION_CALL,uri);
//don't forget add this config:

//send sms/mms
//call sender program
Intent it = new Intent(Intent.ACTION_VIEW);   
it.putExtra("sms_body", "The SMS text");   
it.setType("vnd.android-dir/mms-sms");   
startActivity(it);  

//send sms
Uri uri = Uri.parse("smsto:0800000123");   
Intent it = new Intent(Intent.ACTION_SENDTO, uri);   
it.putExtra("sms_body", "The SMS text");   
startActivity(it);  

//send mms
Uri uri = Uri.parse("content://media/external/images/media/23");   
Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra("sms_body", "some text");   
it.putExtra(Intent.EXTRA_STREAM, uri);   
it.setType("image/png");   
startActivity(it); 

//send email
 
Uri uri = Uri.parse("mailto:xxx@abc.com");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);

Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");   
it.putExtra(Intent.EXTRA_TEXT, "The email body text");   
it.setType("text/plain");   
startActivity(Intent.createChooser(it, "Choose Email Client"));  

Intent it=new Intent(Intent.ACTION_SEND);     
String[] tos={"me@abc.com"};     
String[] ccs={"you@abc.com"};     
it.putExtra(Intent.EXTRA_EMAIL, tos);     
it.putExtra(Intent.EXTRA_CC, ccs);     
it.putExtra(Intent.EXTRA_TEXT, "The email body text");     
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");     
it.setType("message/rfc822");     
startActivity(Intent.createChooser(it, "Choose Email Client"));   


//add extra
Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");   
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");   
sendIntent.setType("audio/mp3");   
startActivity(Intent.createChooser(it, "Choose Email Client"));

//play media
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);

Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");   
Intent it = new Intent(Intent.ACTION_VIEW, uri);   
startActivity(it);  

//Uninstall
Uri uri = Uri.fromParts("package", strPackageName, null);   
Intent it = new Intent(Intent.ACTION_DELETE, uri);   
startActivity(it);

//uninstall apk
Uri uninstallUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);

//install apk
Uri installUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);

//play audio
Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");
returnIt = new Intent(Intent.ACTION_VIEW, playUri);

//send extra
Intent it = new Intent(Intent.ACTION_SEND);  
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");  
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/eoe.mp3");  
sendIntent.setType("audio/mp3");  
startActivity(Intent.createChooser(it, "Choose Email Client"));

//search
Uri uri = Uri.parse("market://search?q=pname:pkg_name");  
Intent it = new Intent(Intent.ACTION_VIEW, uri);  
startActivity(it);  
//where pkg_name is the full package path for an application  

//show program detail page
Uri uri = Uri.parse("market://details?id=app_id");  
Intent it = new Intent(Intent.ACTION_VIEW, uri);  
startActivity(it);  
//where app_id is the application ID, find the ID  
//by clicking on your application on Market home  
//page, and notice the ID from the address bar


//search google
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,"searchString")
startActivity(intent);


아스키코드표

Programming/C,CPP,CS 2013. 5. 2. 22:04 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

DEC Char DEC Char DEC Char
0 Ctrl-@ NUL 43 + 86 V
1 Ctrl-A SOH 44 , 87 W
2 Ctrl-B STX 45 - 88 X
3 Ctrl-C ETX 46 . 89 Y
4 Ctrl-D EOT 47 / 90 Z
5 Ctrl-E ENQ 48 0 91 [
6 Ctrl-F ACK 49 1 92 \
7 Ctrl-G BEL 50 2 93 ]
8 Ctrl-H BS 51 3 94 ^
9 Ctrl-I HT 52 4 95 _
10 Ctrl-J LF 53 5 96 `
11 Ctrl-K VT 54 6 97 a
12 Ctrl-L FF 55 7 98 b
13 Ctrl-M CR 56 8 99 c
14 Ctrl-N SO 57 9 100 d
15 Ctrl-O SI 58 : 101 e
16 Ctrl-P DLE 59 ; 102 f
17 Ctrl-Q DCI 60 < 103 g
18 Ctrl-R DC2 61 = 104 h
19 Ctrl-S DC3 62 > 105 i
20 Ctrl-T DC4 63 ? 106 j
21 Ctrl-U NAK 64 @ 107 k
22 Ctrl-V SYN 65 A 108 l
23 Ctrl-W ETB 66 B 109 m
24 Ctrl-X CAN 67 C 110 n
25 Ctrl-Y EM 68 D 111 o
26 Ctrl-Z SUB 69 E 112 p
27 Ctrl-[ ESC 70 F 113 q
28 Ctrl-\ FS 71 G 114 r
29 Ctrl-] GS 72 H 115 s
30 Ctrl-^ RS 73 I 116 t
31 Ctrl_ US 74 J 117 u
32 Space 75 K 118 v
33 ! 76 L 119 w
34 " 77 M 120 x
35 # 78 N 121 y
36 $ 79 O 122 z
37 % 80 P 123 {
38 & 81 Q 124 |
39 ' 82 R 125 }
40 ( 83 S 126 ~
41 ) 84 T 127 DEL
42 * 85 U  

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 활용 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

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

JAVA 실습과제 0303 ~ 0309

실습과제 모음 2013. 3. 3. 15:16 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1. 사용자로부터 이름과 성적을 입력받아

성적 순으로 출력하시오


ex)

이름 : 홍길동

점수 : 90

이름 : 김철수

점수 : 80

이름 : 김영희

점수 : 100


성적순 출력

김영희 100

홍길동 90

김철수 90


'실습과제 모음' 카테고리의 다른 글

JAVA 실습용  (0) 2013.08.07
JAVA 실습 0801  (0) 2013.08.01
실습  (0) 2013.03.02
JAVA 가계부 프로그램  (0) 2013.03.02
JAVA 직원 관리 프로그램 작성  (0) 2013.03.02