AnonymousPotatoのプロフィール

@AnonymousPotato AnonymousPotato
ありがとう数2
質問数0
回答数3
ベストアンサー数
3
ベストアンサー率
100%
お礼率
0%

  • 登録日2010/05/26
  • BufferedReader.readline()で読み込んだ文字列の

    BufferedReader.readline()で読み込んだ文字列の長さがおかしい。 質問させてください。 BufferedReader.readline()を使用して入力した文字列の長さを表示させると、値が正しく表示されません。 例えば、「東京都千代田区」と入力した場合、長さは9と表示されます。 (東京都と入力すると長さは3と表示されます) どなたか原因をご存知ありませんでしょうか。 コードを以下に記載します。 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Question_1_1 { /* * メイン関数 * @param args 起動引数 */ static public void main(String[] args) throws IOException{ InputStreamReader input = new InputStreamReader(System.in); BufferedReader buff = new BufferedReader(input); String str = ""; System.out.println("文字列入力>"); str = buff.readLine(); System.out.println("文字列長さ : " + str.length()); // ストリームを閉じる input.close(); buff.close(); } }

    • ベストアンサー
    • ryu-e
    • Java
    • 回答数1
  • Java初心者です。

    Java初心者です。 デスクトップ等のPC画面内をクリックしたときに、クリックしたよというフラグを取得したいのですが、さっぱりわかりません。 ネットで検索しても、Javaで用意したコンポーネント上をクリックしたというフラグは拾えるのは多数紹介されているのですが・・・(探し方が悪いのかも)。 また、クリックしたところの座標も取得できるようにするつもりです。(←これは、getPointerInfo()で解決できると思っています) お手数ですが、どうぞご教授お願い致します。

    • ベストアンサー
    • truque
    • Java
    • 回答数1
  • webアプリを作ってます。

    webアプリを作ってます。 sqlの箇所で型の不一致stringからstringは変換できませんと 出てきます。 調べてもわかりませんでした。 どこが間違ってるのか教えてください。 package info.searchman; import 省略 public class Dbinsert extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; private ServletContext context; //private Connection connection; public void init(ServletConfig config) throws ServletException { context=config.getServletContext();} public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=Shift_JIS"); PrintWriter out=response.getWriter(); out.println("<html><head><title>Sample199</title></head><body>"); try { int type=0; String name=null; int price=0; String html=null; //Connection con = null; type=Integer.parseInt(request.getParameter("type")); //name= request.getParameterValues("name"); //String name = request.getParameter("name"); name = redecode(request.getParameter("name")); price=Integer.parseInt(request.getParameter("price")); Class.forName("org.postgresql.Driver"); Connection con = DriverManager.getConnection("jdbc:postgresql:postgres","postgres","gokui"); // ステートメントオブジェクトを生成 Statement stmt = con.createStatement(); String values2 = "(\'"+type+"\', \'"+name+"\', \'"+price+"\')"; String sql="INSERT INTO commodity values " + values2 ; stmt.executeUpdate(sql); //ResultSet rs = stmt.executeQuery(sql); out.println("データを登録しました。"); //out.println("</table>"); //rs.close(); stmt.close(); con.close(); } catch(Exception e) { context.log("denaositekoi"); e.printStackTrace(out); } out.println("</body></html>"); out.close(); } private String redecode(java.lang.String parameter) { // TODO 自動生成されたメソッド・スタブ return null; } }

    • ベストアンサー
    • wegrez
    • Java
    • 回答数2