Значения в UTF-8 кодируется как NULL в JSON

Я предлагаю вам использовать класс с именем ConnectionDerby, в который помещается вся логика и параметры для выбора, вставки, обновления, удаления и в качестве встроенной базы данных, которую я компробирую, если база данных уже существует, если не существует, то я ее создал, Я надеюсь, что этот код поможет вам, извините или мой английский, и я новичок, использующий эту базу данных в Java, но я надеюсь, что это поможет вам понять ....

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;

public class ConnectionDerby {

    private Connection conn = null;
    private Statement sttm = null;

    public Connection CrearBD(String query) {
    try {
        //Obtenemos el Driver de Derby
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        conn = DriverManager.getConnection("jdbc:derby:.\\BD\\nombrebasededatos.db;create=true");
        if (conn != null) {
            //JOptionPane.showMessageDialog(null, "Base de Datos Lista");
            try {
                PreparedStatement pstm = conn.prepareStatement(query);
                pstm.execute();
                pstm.close();
                //JOptionPane.showMessageDialog(null, "Base de Datos Creada Correctamente");
                System.out.println("SENTENCIA SQL EFECTUADA CORRECTAMENTE");
            } catch (SQLException ex) {
                //JOptionPane.showMessageDialog(null, ex.getLocalizedMessage());
                System.out.println(ex.getMessage());
                JOptionPane.showMessageDialog(null, "NO SE PUDO EFECTUAR LA SENTENCIA SQL", "Error", JOptionPane.ERROR_MESSAGE);
                //JOptionPane.showMessageDialog(null, "NO SE PUDO EFECTUAR LA SENTENCIA SQL");
            }
        }

    } catch (SQLException e) {
        System.out.println(e.getMessage());
        JOptionPane.showMessageDialog(null, "NO SE PUDO EFECTUAR LA SENTENCIA SQL", "Error", JOptionPane.ERROR_MESSAGE);
        //JOptionPane.showMessageDialog(null, "TRONO LA APLICACION EN EJECUTAR LAS SENTENCIAS SQL parte 2");
    } catch (ClassNotFoundException e) {
        System.out.println(e.getMessage());
        JOptionPane.showMessageDialog(null, "NO SE PUDO EFECTUAR LA SENTENCIA SQL", "Error", JOptionPane.ERROR_MESSAGE);
        //JOptionPane.showMessageDialog(null, "TRONO LA APLICACION EN EJECUTAR LAS SENTENCIAS SQL parte 3");
    }
    return conn;
}

public Connection AccederBD() {
    try {
        //Obtenemos el Driver de Derby
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        //Obtenemos la Conexión
        conn = DriverManager.getConnection("jdbc:derby:.\\BD\\nombrebasededatos.db");
        if (conn != null) {
            System.out.println("Base de Datos Ya Leida Correctamente");
            //JOptionPane.showMessageDialog(null, "Base de Datos Ya Leida Correctamente");
        }
    } catch (SQLException e) {
        System.out.println(e.getMessage());
        System.out.println("Sistema Creado por Mario José Echeverría");
        System.out.println("NO SE ENCONTRO LA BASE DE DATOS");
        System.out.println("CREANDO BASE DE DATOS EN DERBY DATABASE");
        String createTableProyecto = "Sentence to create first table";
        String createTablePrimer = "Sentence to create second table";
        String createTableTopCoat = "Sentence to create third table";
        String createTableCotizacion = "Sentence to create fourth table";
        CrearBD(createTableProyecto);
        CrearBD(createTablePrimer);
        CrearBD(createTableTopCoat);
        CrearBD(createTableCotizacion);
        //*************PRUEBAS*****************
    } catch (ClassNotFoundException e) {
        System.out.println(e.getMessage());
        System.out.println("ERROR DE TIPO ClassNotFoundException");
        //JOptionPane.showMessageDialog(null, "TRONO LA APLICACION EN ACCEDER A LA BASE DE DATOS parte 2");
    }
    return conn;
}

public void UID(String sqlcad) {
    try {
        //Obtenemos el Driver de Derby
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        conn = DriverManager.getConnection("jdbc:derby:.\\BD\\nombrebasededatos.db");
        sttm = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        sttm.executeUpdate(sqlcad);
        System.out.println("Conexión Exitosa a la Base de Datos");
        //JOptionPane.showMessageDialog(null, "Conexión exitosa");
        sttm.close();
        conn.close();
        if (conn != null) {
            System.out.println("Consulta Realizada Correctamente");
            //JOptionPane.showMessageDialog(null, "Base de Datos Ya Leida Correctamente");
        }
    } catch (SQLException e) {
        System.out.println("Error= " + e.getMessage());
    } catch (ClassNotFoundException e) {
        System.out.println("Error= " + e.getMessage());
    }
}

public ResultSet getvalores(String sqlcad) {
    ResultSet rs = null;
    try {
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        conn = DriverManager.getConnection("jdbc:derby:.\\BD\\nombrebasededatos.db");
        sttm = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        //String sqlcad = "Select nombre, m2xgal, pregal, precub, descripcion from primer";
        rs = sttm.executeQuery(sqlcad);
        return rs;
    } catch (Exception e) {
        System.out.println("Error= " + e.getMessage());
        return rs;
    }
}
}
21
задан Herman Schaaf 17 October 2011 в 07:49
поделиться

2 ответа

Благодарим Дэвида Мердока по адресу http://www.vervestudios.co/ за предоставленный полезный ответ:

$.ui.autocomplete.prototype._renderItem = function( ul, item){
  var term = this.term.split(' ').join('|');
  var re = new RegExp("(" + term + ")", "gi") ;
  var t = item.label.replace(re,"<b>$1</b>");
  return $( "<li></li>" )
     .data( "item.autocomplete", item )
     .append( "<a>" + t + "</a>" )
     .appendTo( ul );
};
$("#keyword").autocomplete({ 
  source: "ajax/autocomplete.php?action=keyword", 
  minLength: 2 
});
32
ответ дан 29 November 2019 в 21:05
поделиться

Мысль Сомоне может найти это полезным. это полный документ HTML, который использует вышеупомянутые принципы. Я использовал его в качестве прототипа для некоторых моих работ.

    <html xmlns="http://www.w3.org/1999/xhtml">

    <!--

        orders.html simply returns the following text

        Basketball#Football#Baseball#Helicopter#gubbins#harry potter#banyan


    -->

    <head id="Head1" runat="server">
        <title>AutoComplete Box with jQuery</title>
        <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css"
            rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
        <script type="text/javascript">

            function loadData() {

                var sURL = "orders.htm";

                $.ajaxSetup({ cache: false });

                $.ui.autocomplete.prototype._renderItem = function (ul, item) {
                    var term = this.term.split(' ').join('|');
                    var re = new RegExp("(" + term + ")", "gi");
                    var t = item.label.replace(re, "<b>$1</b>");
                    return $("<li></li>")
                    .data("item.autocomplete", item)
                    .append("<a>" + t + "</a>")
                    .appendTo(ul);
                };

                $.get(sURL, function (responseText) {
                    data = responseText.split('#');

                    $("#txtSearch").autocomplete({
                        //source: availableSports
                        source: data,
                        minLength: 2 

                    });

                });

            }

        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div class="demo">
            <div class="ui-widget">
                <label for="tbAuto">
                    Enter data:
                </label>
                <input type="text" id="txtSearch" class="autosuggest" onkeyup="loadData();" />
            </div>
        </form>
    </body>
    </html>

Надеюсь, это поможет кому-то, так же, как и мне.

2
ответ дан 29 November 2019 в 21:05
поделиться
Другие вопросы по тегам:

Похожие вопросы: