unity3d链接postgresql,读数据库内容并且显示(读出的中文在编辑器中乱码,发布standalone正常)
来源:互联网 发布:java实验fan 编辑:程序博客网 时间:2024/06/04 22:47
新建一个场景,此脚本挂着相机上,同时提前在网站http://blog.csdn.net/FlashDragon/article/details/4789980准备工作(如导入Npgsql.dll和System.Data.dll)
using UnityEngine;using Npgsql;using System.Data;public class postgresql : MonoBehaviour{ string strConnec; string strSelect; string strResult; NpgsqlConnection conn; /// <summary> /// 静态读取txt /// </summary> public TextAsset txtYxx; string strYxx; /// <summary> /// Resources /// </summary> string strYtext; // Use this for initialization void Start() { //strYxx = txtYxx.text; //print("读取的yxx.txt内容为:"+strYxx); //strYtext = ((TextAsset)Resources.Load("ytest")).text; //print(strYtext); try { //192.168.1.222 strConnec = "Server=192.168.1.234;Port=5432;User Id=postgres;Password=root;Database=gafk"; //strConnec = "Server=192.168.1.222;Port=5432;User Id=postgres;Password=root;Database=postgres"; // strConnec = "Server=192.168.1.123;Port=5432;User Id=postgres;Password=root;Database=lucky;"; //charset ='utf8'"; conn = new NpgsqlConnection(strConnec); conn.Open(); if (conn.State == ConnectionState.Open) { print("Connection is on!"); //strSelect = "SELECT mc FROM zydd WHERE \"id\"='4028816a57e025bc0157e0c18b8c0027'";//单行查询 strSelect = "SELECT mc,dm FROM zyll_local WHERE xxlb='8'"; //多行查询 //strSelect = "select name from luck where id='1'"; // strSelect = "select name from yxx where id ='1'"; } } catch (System.Exception ex) { print(ex); } } void OnGUI() { GUILayout.Label(" "); if (GUILayout.Button("connect to server")) { DataSet ds = new DataSet(); NpgsqlDataAdapter da = new NpgsqlDataAdapter(strSelect, conn); da.Fill(ds); foreach (DataTable table in ds.Tables) { print("ds.Tables.Count;" + ds.Tables.Count); foreach (DataRow row in table.Rows) { print("table.Rows.Count;" + table.Rows.Count); foreach (DataColumn column in table.Columns) { print("table.Columns.Count;" + table.Columns.Count); print(" 第1张表第2行2列数据是:" + ds.Tables[0].Rows[1][1]); //strResult = row[column].ToString(); //print("1:" + row[column].ToString()); //print(); } } } } GUILayout.Label(strResult); } /* * 解决unity3d读写中文乱码 //http://www.tuicool.com/articles/BriMR3 * */ //public void Read() //{ // try // { // string pathSource = "test.txt"; // using (FileStream fsSouce = new FileStream(pathSource, FileMode.Open, FileAccess.Read)) // { // byte[] bytes = new byte[fsSouce.Length]; // int numBytesToRead = (int)fsSouce.Length; // int numbytesRead = 0; // while (numBytesToRead>0) // { // int n = fsSouce.Read(bytes, numbytesRead, numBytesToRead); // if (n==0) // { // break; // } // numbytesRead += n; // numBytesToRead -= n; // } // numBytesToRead = bytes.Length; // string str= UTF8Encoding.UTF8.GetString(bytes); // } // } // catch (System.Exception) // { // throw; // } //}}
即将访问的数据库结构为:
运行中图为:
0 0
- unity3d链接postgresql,读数据库内容并且显示(读出的中文在编辑器中乱码,发布standalone正常)
- MySql中读出的中文乱码问题
- fread读数据到缓冲区中时,在参数设置正确的情况下,不能够读出整个文件。
- java文件在eclipse工程里中文显示方框乱码,用记事本中打开显示正常
- Ubuntu中Atom编辑器显示中文乱码的处理方法
- 中文乱码问题,Eclipse能正常显示,但在tomcat部署工程中不行
- PHP 读数据库中文乱码
- jsp 中提交表单后在firefox、chrome 中中文显示为正常,但在IE中中文显示为乱码?
- JFreeChart中文显示乱码,英文正常的solution
- Weblogic: 在weblogic8.1中显示中文乱码的解决方法
- jsp在浏览器中显示中文的乱码问题解决
- 自己编写的中文网页在浏览器中显示乱码
- 织梦dedecms后台编辑器鼠标放在多图发布按钮上显示乱码的解决方法
- eclipse中ant在中文目录下乱码并且不能运行的解决方法
- 英文操作系统中,CMD显示中文乱码问题;让Google chrome正常显示中文
- 中文数据在JSP中显示乱码
- QT 在lineEdit中显示中文乱码
- 发布后中文显示乱码
- JAVA 容器总结 v1.0
- java基于ajax实现验证码
- uboot中flash调用
- JAVA ffmpeg 视频处理
- 多个git帐号的切换
- unity3d链接postgresql,读数据库内容并且显示(读出的中文在编辑器中乱码,发布standalone正常)
- html(四)_表格,列表,区块
- 图的储存方式
- 小程序开发补坑
- STL遍历算法 “for_each ”,“transform”
- 简单学正则表达式
- Spring中scope作用域(转)
- Android 6.0 PowerManagerService 一
- liux环境下修改mysql编码