---
# System prepended metadata

title: 我的筆記
tags: [筆記本]

---

# 我的筆記
###### tags: `筆記本`
````````


	
			try {
				String connUrl = "jdbc:sqlserver://localhost:1433;databaseName=MyDB";
				java.sql.Connection conn = DriverManager.getConnection(connUrl, "sa", "manager");
				
				
				
				FileReader fr = new FileReader("C:\\test.csv");
	            BufferedReader brdFile = new BufferedReader(fr);//bufferedReader
	            String strLine = null;
	            while((strLine = brdFile.readLine())!=null){/
	            
	            
				
				String[] array=strLine.split(",");
				System.out.println(strLine);
				for(int i=0;i<array.length;i++){
			System.out.println(array[i]);
				}
				String qryInsert="insert into [dbo].[MyDB]\r\n"
						+ "           ([越區]\r\n"
						+ "           ,[Jan]\r\n"
						+ "           ,[Feb]\r\n"
						+ "           ,[Mar]\r\n"
						+ "           ,[Apr]\r\n"
						+ "           ,[May]\r\n"
						+ "           ,[Jun]\r\n"
						+ "           ,[Jul]\r\n"
						+ "           ,[Aug]\r\n"
						+ "           ,[Sep]\r\n"
						+ "           ,[OCT]\r\n"
						+ "           ,[NOV]\r\n"
						+ "           ,[DEC]) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
						
				PreparedStatement pstmt= conn.prepareStatement(qryInsert);//因為是insert所以用PreparedStatement來接
				
				pstmt.setString(1,array[0]);
				pstmt.setString(2,array[1]);
				pstmt.setString(3,array[2]);			
				pstmt.setString(4,array[3]);
				pstmt.setString(5,array[4]);
				pstmt.setString(6,array[5]);
				pstmt.setString(7,array[6]);
				pstmt.setString(8,array[7]);
				pstmt.setString(9,array[8]);
				pstmt.setString(10,array[9]);
				pstmt.setString(11,array[10]);
				pstmt.setString(12,array[11]);
				pstmt.setString(13,array[12]);
				
				pstmt.execute();
				};
			}catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}catch (IOException e) {
					// TODO Auto-generated catch block
				e.printStackTrace();
			}catch (SQLException e){
					// TODO Auto-generated catch block
				e.printStackTrace();
			}

	